Hey there! any question in your mind? Ask It Now!.

Popular Categories





JavaScript: Select and Delect all check box on click one check box

+1 vote
103 views
asked in Programming by payel (1,640 points)
I want to Select and Delect all check box on click one check box i am using html and java script

Thanks for your answer!

2 Answers

0 votes
answered by Eathen (1,930 points)
Use  this script
<script type="text/javascript">
checked=false;
function checkedAllBox (formID) {
var aa= document.getElementById('formID');
if (checked == false)
          {
           checked = true
          }
        else
          {
          checked = false
          }
for (var i =0; i < aa.elements.length; i++) 
{
aa.elements[i].checked = checked;
}
      }
</script>
This is form 
<form id ="formID"> 
<input type="checkbox" name="chkbox1">
<input type="checkbox" name="chkbox2">
</form>
here is the checkbox which will select and deselect all checkboxes 
 <input type='checkbox' name='checkall' onclick='checkedAllBox(formID)'>
 

 

0 votes
answered by amit_pammu Expert (5,030 points)
  1. function checkCheckboxes() {
  2.     var e = document.getElementsByName("delId");
  3.     var message  = 'Are you sure you want to delete?';
  4.     var row_list = {length: 0};
  5.  
  6.     for (var i = 0; i < e.length; i++) {
  7.         var c_box = e[i];
  8.  
  9.         if (c_box.checked == true) {
  10.             row_list.length++;
  11.  
  12.             row_list[i] = {};
  13.             row_list[i].row = c_box.parentNode.parentNode;
  14.             row_list[i].tb  = row_list[i].row.parentNode;
  15.         }
  16.     }
  17.  
  18.     if (row_list.length > 0 && window.confirm(message)) {
  19.         for (i in row_list) {
  20.             if (i == 'length') {
  21.                 continue;
  22.             }
  23.  
  24.             var r = row_list[i];
  25.             r.tb.removeChild(r.row);
  26.         }
  27.     } else if (row_list.length == 0) {
  28.         alert('You must select an email address to delete');
  29.     }
  30. }

    use this it might be helpful!


 

Related Questions

+1 vote
1 answer 729 views
+4 votes
5 answers 1,987 views
+1 vote
1 answer 636 views
+1 vote
1 answer 75 views
+1 vote
2 answers 154 views
+5 votes
2 answers 1,131 views

Not a Member yet?

Ask to Folks Login

My Account
134 Folks are online
0 members and 134 guest online
Your feedback is highly appreciated