How to Get Checked and Unchecked Checkbox Value in jQuery

Now, I have to show you some easily understood examples for how to get checked and unchecked checkbox value in jquery. As well as, given source code using jquery and explain in detail get checkbox value different ways.

Also, we describe a few events relative to this topic. Afterward, get multiple checkboxes with the use of the jquery selector.

As an example, add and remove the checkbox value events from the array using jquery. Now, you can see the example in the below section.

How to Get Checked and Unchecked Checkbox Value in jQuery

Firstly, create an HTML structure and added a few checkboxes under the HTML form.

<!-- $('.checkbox').prop('checked', true);  //false for uncheck
//jQuery 1.5.x and below use
$('.checkbox').attr('checked', true);  //false for uncheck -->

<!DOCTYPE html>
<html>
<head>
	<title>Checked and unchecked value</title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
		
</head>
<body>
<section>
<h1>My Selected Color</h1>
<form >
	Red<input type="checkbox" class="red" name="" value="red"><br/>
	Green<input type="checkbox" class="green" name="green" value="green"><br/>
	Blue<input type="checkbox" class="blue" name="blue"><br/>	
	White<input type="checkbox" class="white" name="white"><br/>	
	<input type="button" id="submit" name="submit" value="submit">
</form>
<div class="showCheckedValue"></div>
</section>
<script type="text/javascript">

	/********Button Click Event get multiple value********/	
	$('#submit').click(function(){
		var redval = $('.red').val();
		var grenval = $('.green').val();
		$('.showCheckedValue').text(redval+'&'+grenval );
	});
	
</script>
</body>
</html>

Above all, given a script get check value by click. So, I added classes to each input and also added a class in button.

After that, implement a click event using the button class name is ‘submit’. secondly, using select event and get check input value by click. You can see out in the below section.

Note:- focus on class and id name which you add is selected. As well, the main jquery tags use ‘this’ to get the value of checked and unchecked

how to get checked and unchecked checkbox value in jquery

Even, we created a simple form to display multiple checkbox fields. Afterward, we have to give an example in the below code go and follow this code.

<form >
 Red<input type="checkbox" class="red" name="" value="red"><br/>
 Green<input type="checkbox" class="green" name="green" value="green"><br/>
 Blue<input type="checkbox" class="blue" name="blue"><br/> 
 White<input type="checkbox" class="white" name="white"><br/> 
 <input type="button" id="submit" name="submit" value="submit">
</form>

After that, you use this code to create an input form then write a functionally of jquery. As well, jquery set checkbox checked based on value. Accordingly, follow the below section and see the full jquery code.

$('#submit').click(function(){
 var redval = $('.red').val();
 var grenval = $('.green').val();
 $('.showCheckedValue').text(redval+'&'+grenval );
 });

in the final analysis, there is a click event when click the submit button. So, you can get the input value at a variable. Such as we have to use multiple variables to get checkbox check value from this method.

How to Check Checkbox is Checked or not in jquery on Button Click

Similarly, the above example and this point both are the same but these additions of conditions check and uncheck the checkbox. So, I am going to start with the code of the example. Which you can easily understand all points.

.

 $(document).ready(function(){     
   $(".clickbtn").click(function(){        
       $("#checkbox1").prop("checked", true);    
 });     
$(".clicbtn-unchecked").click(function(){         
$("#checkbox1").prop("checked", false);    
 }); 
}); 

Now, we have provided a syntax of line. Whom you use the conditions to change checked and unchecked checkbox this condition prop().

$("#checkbox1").prop("checked", false); 

Above, display a condition with jquery prop(). So, We can pass two parameters in this function like can see above syntax. If you want to check the value from the checkbox to mention true otherwise should be used false to change automatically checkbox checked and unchecked with the conditions.

$("#checkbox1").prop("checked", true); 

Specifically, here is some relative important topic to follow and get code with the example.

Conclusion

finally, display all examples of How to Get Check and Unchecked Checkbox Value in jQuery. If you have any query and suggest with this post should ask anytime. Also, you can put your query in the comment section. I have to reply as shortly.

One Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

Related Post

Submit Form without Page Refresh using Ajax jQuery PHP

Here, we are going to start about submit a form without page refresh using Ajax jQuery and Php with the example. Also, explain and given some code to ajax serialize form data example without reloading the page. As well as, submit form and show results on the same page without a refresh. Thus, showing the […]

Read more

How to Remove Last Character From String jQuery

We are providing the simple best method to remove last character from string jquery. Also, given an example of code delete the last character from string using jquery. Thus, you can see from string and input both types might remove the last character in the post. Here, The main code function of a slice(). which […]

Read more

How to Get href Value of Anchor Tag in jQuery

Here, I am displaying how to get href value of anchor tag in jquery. Also, given some examples of multiple ways to implement to get href value using jquery. Note: Firstly require jquery library CDN link. As well as, know about jquery selector and get attributes. Follow the below section steps. Get href Value of […]

Read more

x