article

Wednesday, September 25, 2019

How to get the values of Select All Checkbox using jQuery

How to get the values of Select All Checkbox using jQuery <!DOCTYPE html> <html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to get the values of Select All Checkbox using jQuery</title>
<SCRIPT language="javascript">
$(document).ready(function() {
 // add multiple select / deselect functionality
 $("#selectall").click(function () {
  $('.item').attr('checked', this.checked);
 });
 // if all checkbox are selected, check the selectall checkbox and viceversa
 $(".item").click(function(){
  if($(".item").length == $(".item:checked").length) {
   $("#selectall").attr("checked", "checked");
  } else {
   $("#selectall").removeAttr("checked");
  }
 });
 //get the values of selected checkboxes
 $("button").click(function(){
  var favorite = [];
  $.each($("input[name='programming']:checked"), function(){           
   favorite.push($(this).val());
  });
  alert("My favourite Programming are: " + favorite.join(", "));
    });
});
</SCRIPT>
</head>
<body>
<form>
<p><h1>How to get the values of Select All Checkbox using jQuery</h1></p>
<label>Select your favorite programming  <br/>
Select All Checkbox <input type="checkbox" id="selectall"/></label><br/>
<input type="checkbox" name="programming" class="item" value="Jquery"/>
Jquery<br/>
<input type="checkbox" name="programming" class="item" value="php mysql"/>
php mysql<br/>
<input type="checkbox" name="programming" class="item" value="3"/>
Java<br/>
<input type="checkbox" name="programming" class="item" value="4"/>
Javascript<br/>
<input type="checkbox" name="programming" class="item" value="5"/>
Python<br/>
<input type="checkbox" name="programming" class="item" value="6"/>
Ruby<br/>
<button type="button">Get Values</button>
</form>
</html>

Related Post