473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

uncheck checkboxes within single div

I need to zero in on a specific section of my jsp form during a hide to uncheck the checkboxes in that section. Currently, anything I try either unchecks all checkboxes on the form or doesn't work at all. When I associated the specific section with ID the first box within the div is unchecked but not the second.

Suggestions?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div id="menu1" class=hide>
  3.  
  4.  <div id="col1">
  5.  <input type="checkbox"  name="Topic"  value="_topic1" />topic 1 </div>
  6.  <div id="col2">
  7.  <input type="checkbox" name="Topic" value="_topic2" />topic 2 </div>
  8.  
  9.  <div id="exit"><img src="/img/exit.gif" onclick="uncheck('menu1')" /></div>
  10. </div>
  11.  
  12. <div id="menu2" class=hide>
  13.  
  14.  <div id="col1">
  15.  <input type="checkbox"  name="Topic"  value="_topic3" />topic 3 </div>
  16.  <div id="col2">
  17.  <input type="checkbox" name="Topic" value="_topic4" />topic 4 </div>
  18.  
  19. <div id="exit"><img src="/img/exit.gif" onclick="uncheck('menu2')" /></div>
  20.  
  21. </div>
  22.  
  23. <div id="col1"> // always visable.
  24.  <div><input type="checkbox" name="Topic" value="_main1" /> main 1</div>
  25.  <div><input type="checkbox" name="Topic" value="_main2" /> main 2 </div>
  26.  <div><input type="checkbox" name="Topic" value="_main3" /> main 3 </div> 
  27. </div>
  28.  
  29.  
-html
Expand|Select|Wrap|Line Numbers
  1.  
  2. function uncheck()
  3.  {
  4.      document.getElementById("Topic").checked=false
  5.  }
  6.  
  7. ///  or  ////
  8.  
  9. function uncheck2(formname,checkname,state){
  10.     var checkboxes=eval("document.forms."+formname+"."+checkname)
  11.     for (cb=0;cb<checkboxes.length;cb++)
  12.     checkboxes[cb].checked=state    
  13. }
  14.  
  15.  
- javascript
Sep 24 '07 #1
12 4023
pbmods
5,821 Expert 4TB
Heya, Swebster.

Why is there an eval() in this line?
Expand|Select|Wrap|Line Numbers
  1. var checkboxes=eval("document.forms."+formname+"."+checkname)
  2.  
This will work just as well, and more efficiently, to boot:
Expand|Select|Wrap|Line Numbers
  1. var checkboxes = document.forms[formname][checkname];
  2.  
But more importantly, document.forms[formname][checkname] only represents a singe element.

You will want to use getElementsByTagName().
Sep 24 '07 #2
You will want to use getElementsByTagName().
eval was incorrectly placed you're right..

In terms of tagName, would it be something simlar to; So by marking the tagname to div or id and using the jsf with the div in question it will uncheck those boxes?

Expand|Select|Wrap|Line Numbers
  1. < onclick="uncheck2('menu1')" 
  2.  
- html

Expand|Select|Wrap|Line Numbers
  1. document.getElementsByTagName("div").checked=false
  2.  
- javascript
Sep 24 '07 #3
by setting the exact menu in the function below, the checkbox objects are set to false during onclick and the main checkboxes are untouched. With multiple menus to thing of a function would be needed for each one of them so there must be a more intelligent way. This deployment is in IE which is why I am using getAttribute. getAttribute('class') == 'show' works too but sets all the visible menu options to false and there are 20. Also, an error is returned with using a wildcard 'menu*' or 'menu[1-20]

Suggestions? Thanks

Expand|Select|Wrap|Line Numbers
  1.     function uncheck() {
  2.         var ins = document.getElementsByTagName('input');
  3.         for (var i=0; i<ins.length; i++) {
  4.         if (ins[i].getAttribute('id') == 'menu1') ins[i].checked =
  5.         false;
  6.         }
  7.     }
  8.  
  9.  
- javascript

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div id="menu1" class=hide>
  3.  
  4.  <div id="col1">
  5.  <input type="checkbox"  name="Topic"  value="_topic1" />topic 1 </div>
  6.  <div id="col2">
  7.  <input type="checkbox" name="Topic" value="_topic2" />topic 2 </div>
  8.  
  9.  <div id="exit"><img src="/img/exit.gif" onclick="uncheck()" /></div>
  10. </div>
  11.  
  12. <div id="menu2" class=hide>
  13.  
  14.  <div id="col1">
  15.  <input type="checkbox"  name="Topic"  value="_topic3" />topic 3 </div>
  16.  <div id="col2">
  17.  <input type="checkbox" name="Topic" value="_topic4" />topic 4 </div>
  18.  
  19. <div id="exit"><img src="/img/exit.gif" onclick="uncheck()" /></div>
  20.  
  21. </div>
  22.  
  23. <div id="col1"> // always visable.
  24.  <div><input type="checkbox" name="Topic" value="_main1" /> main 1</div>
  25.  <div><input type="checkbox" name="Topic" value="_main2" /> main 2 </div>
  26.  <div><input type="checkbox" name="Topic" value="_main3" /> main 3 </div> 
  27. </div>
  28.  
  29.  
  30.  
- html
Sep 24 '07 #4
pbmods
5,821 Expert 4TB
Heya, Swebster.

Each Element has the getElementsByTagName() method:
Expand|Select|Wrap|Line Numbers
  1. var inputs = document.getElementById('divId').getElementsByTagName('input');
  2.  
Sep 24 '07 #5
Pbmods,

including a checkbox=false statement triggering on the div id='menu * ' within the existing showhide function might be a little cleaner. Would you be able to assist?


Expand|Select|Wrap|Line Numbers
  1.  
  2. function checkall(formname,checkname,state){
  3.     var checkboxes=eval("document.forms."+formname+"."+checkname)
  4.     for (cb=0;cb<checkboxes.length;cb++)
  5.     {
  6.     var obj = checkboxes[cb];
  7.     if(obj.parentNode.parentNode.className!='hide')
  8.     {
  9.     obj.checked=state;
  10.     }
  11.     }
  12. }
  13.  
- javascript
Sep 25 '07 #6
[quote=swebster]Pbmods,

At a glance can you determine what is being done wrong here?
The function is not setting the specific checkboxes to false.

Thank you for your time.


Expand|Select|Wrap|Line Numbers
  1.  
  2. function resetCheckkboxes() {
  3. var inputs = document.getElementsById('divId').getElementsByTagName('input');
  4.     for (var i=0; i<inputs.length; i++) 
  5.      {        
  6.          var obj = inputs[i];
  7.          if(obj.checkbox!='false')
  8.          {
  9.          obj.checked='false';
  10.          }
  11.     }
  12. }
  13.  
- javascript
Oct 1 '07 #7
Heya, Swebster.

Each Element has the getElementsByTagName() method:
Expand|Select|Wrap|Line Numbers
  1. var inputs = document.getElementById('divId').getElementsByTagName('input');
  2.  
This returns an error;

Object doesn't support this property or method.

Expand|Select|Wrap|Line Numbers
  1. function resetCheckboxes() {
  2. var inputs = document.getElementsById('divId').getElementsByTagName('input');
  3. for (var i=0; i<inputs.length; i++) 
  4.   {
  5.     var obj = inputs[i];
  6.      if(obj.checkbox!='false')
  7.   {
  8.      obj.checked='false';
  9.      }
  10.  }
  11. }
  12.  
  13.  
- javascript
Oct 9 '07 #8
acoder
16,027 Expert Mod 8TB
This returns an error;

Object doesn't support this property or method.
It's getElementById, not getElementsById.

You also seem to have multiple objects with the same id. That is incorrect. An id should be unique.
Oct 9 '07 #9
It's getElementById, not getElementsById.

You also seem to have multiple objects with the same id. That is incorrect. An id should be unique.
Thanks for the correction on getElementById. I now have a more clear error message.

'document.getElementById(...)' is null or not an object.

In terms of multiple objects, I have update the code to only have unique div id's for each of the menus and the checkboxes are now using class rather than div id.
Oct 9 '07 #10
acoder
16,027 Expert Mod 8TB
Check that you have a div with the ID that you're using.
Oct 9 '07 #11
Check that you have a div with the ID that you're using.
Got it. thanks for all your suggestions.

Here is the correct code for the forum..

Expand|Select|Wrap|Line Numbers
  1. function unselect(theid) {
  2.   var inputs = document.getElementById(theid).getElementsByTagName('input');
  3.        for (var i=0; i<inputs.length ; i++)
  4.            {
  5.            var obj = inputs[i];
  6.            if(inputs[i].type == "checkbox") {
  7.            inputs[i].checked=false;
  8.            }
  9.        }
  10.   }
  11.  
-javascript
Oct 9 '07 #12
acoder
16,027 Expert Mod 8TB
Glad to hear you got it working and thanks for posting the solution.

Post again if you have any more queries.
Oct 9 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: John Banta | last post by:
Hi, I have created a 12 month calendar where each day has a check box whereby the user can indicate if that day is available or not available for a certain event. The calendar is 'drawn' in a...
4
by: Sileesh | last post by:
Hi I have datagrid with 8 items. Out of which 2 items are checkboxes. Data is binded dynamically to the datagrid Based on some values from the database I have to check or uncheck the checkbox...
2
by: Rekha | last post by:
Hi I have datagrid with 5 items. Out of which 1 items are checkboxes. The bool column(checkbox column ) in added in datagrid. The rest of Data is binded dynamically to the datagrid Based on...
5
by: Mike Fellows | last post by:
I have created some checkboxes within a panel using the code below Dim NewCheckbox As New CheckBox Me.Panel2.Controls.Add(NewCheckbox) NewCheckbox.Location = New Point(XLocation, YLocation)...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
3
by: BibhuAshish | last post by:
Hi, I want to check or uncheck a number of checkboxes by clicking an image. My html code is given below: <TABLE> <TR> <TD>
8
by: PeteOlcott | last post by:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_change_structure.html I would like to completely understand how GUI controls such as this one are constructed. In the...
1
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
14
by: dragon52 | last post by:
Hi Everyone, Not sure the following is possible to do. The standard MS Access user interface has checkboxes on a number of menu pages, such as Tools/Options/View. I have been asked to find a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.