Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes select and unselecting checkboxes based on clicking a check box 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 "select and unselecting checkboxes based on clicking a check box" Watch "select and unselecting checkboxes based on clicking a check box" New topic
Author

select and unselecting checkboxes based on clicking a check box

shyamkumar bopannachengalaiah
Ranch Hand

Joined: Dec 30, 2008
Posts: 100
I have a check box name "select" and and also some four check boxes named as "child". when i click or check the "select" check box all the child check box has to be checked and when i unselect or uncheck the "select" box ,all the child check boxes has to be unchecked. I have done this task using javascript. My problem is that when i uncheck atleast a "child" checkbox automatically the "select" check box has to be unselected. How can i do this using javascript?If there is any example available kindly publish here.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
when click of select checkbox you calling JS function in that you are checking all child checkboxes I guess.

same way when you click on any child checkbox call another JS function in that get all child checkbox & check if any one of them is unchecked then uncheck select checkbox.


Thanks,
Shailesh
Romit Bose
Ranch Hand

Joined: Oct 03, 2007
Posts: 50
hi,
how about writing one generic function which handles all the checkboxes? say you have a javascript method called
handleCheckBoxes(key) and you pass "this", that is, the reference to that box on whose selection you are calling the method.
Now, inside the method, its simply writing the conditions and selecting or unselecting the boxes, right?
shyamkumar bopannachengalaiah
Ranch Hand

Joined: Dec 30, 2008
Posts: 100
Shail Narkhede wrote:when click of select checkbox you calling JS function in that you are checking all child checkboxes I guess.

same way when you click on any child checkbox call another JS function in that get all child checkbox & check if any one of them is unchecked then uncheck select checkbox.



Is there any examples available?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Searching the forum might be a good start: http://www.coderanch.com/forums/jforum?module=search&action=search&forum=20&match_type=all&sort_by=time&search_keywords=Check+All+Checkboxes

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: select and unselecting checkboxes based on clicking a check box
 
Similar Threads
refresh parent window on closing of child window
Retrieving list of values from select box using javascript
Auto tabbing among text fields created with logic:iterate
code in jsp for check all button
Operations between two select boxes