This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: code in jsp for check all button
 
Similar Threads
select and unselecting checkboxes based on clicking a check box
checkbox values in session
How do we maintain the checkbox status while doing sorting in the display tag
Problem While using check boxes
checkbox selection problem