File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes code in jsp for check all button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "code in jsp for check all button" Watch "code in jsp for check all button" New topic
Author

code in jsp for check all button

nikhil govind
Ranch Hand

Joined: Mar 08, 2011
Posts: 31
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

Joined: Jul 20, 2006
Posts: 53
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code in jsp for check all button