• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code in jsp for check all button

 
nikhil govind
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
var checked = false;
function checkAll()
{
if(checked == false){
checked = true;
}
else{
checked = false;
}
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
inputs[i].checked = checked;



}
}
}

this has the problem that when we click on check all box it work fine and when we click again it unchecks working fine
but when any sub check boxes are un-selected then if the select all check box was checked it doesnt get removed
so what modification to do to remove the tick mark if sub check boxes are deselected

 
Ravishanker kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able understand your problem completely. What I understood is, you have a button to check/uncheck all check boxes on the page.
this has the problem that when we click on check all box it work fine and when we click again it unchecks working fine

is this mean when you check/uncheck select all button, that is working fine.
but when any sub check boxes are un-selected then if the select all check box was checked it doesnt get removed

didn't understood this.

You can use following code if "select all" control is also check box,
function checkAll(checkAllButton)
{
var checked = checkAllButton.checked;
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++)
{
if (inputs[i].type == 'checkbox')
{
inputs[i].checked = checked;
}
}
}
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nikhil govind wrote:what modification to do to remove the tick mark if sub check boxes are deselected


You would need event handlers on the chekboxes or a global event handler that see what click actions happened on the page.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic