473,659 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

uncheck checkboxes within single div

34 New Member
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 4042
pbmods
5,821 Recognized Expert Expert
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 getElementsByTa gName().
Sep 24 '07 #2
swebster
34 New Member
You will want to use getElementsByTa gName().
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
swebster
34 New Member
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('c lass') == '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 Recognized Expert Expert
Heya, Swebster.

Each Element has the getElementsByTa gName() method:
Expand|Select|Wrap|Line Numbers
  1. var inputs = document.getElementById('divId').getElementsByTagName('input');
  2.  
Sep 24 '07 #5
swebster
34 New Member
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
swebster
34 New Member
[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
swebster
34 New Member
Heya, Swebster.

Each Element has the getElementsByTa gName() 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 Recognized Expert Moderator MVP
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
swebster
34 New Member
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.getEl ementById(...)' 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

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

Similar topics

8
4020
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 single form rather than 12 separate forms. If the checkbox contained in each day within each month has a unique name such as 1August2003, 2August2003, etc, is there a way in Javascript where I could have a button by each month where the user...
4
2920
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 in the datatgrid. Does any one know how to do this?
2
6051
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 some values from the database I have to check or uncheck the checkbox in the datatgrid. Does any one know how to do this in windows form?
5
8386
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) NewCheckbox.AutoSize = True NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0) NewCheckbox.Name = "Checkbox" & counter1 + 1
10
5195
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. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
3
3359
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
6028
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 ideal case I would like to see all of the source code for a complete working example of a ListBox of CheckBoxes.
1
5178
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 checkboxes (code pasted below). But if name of the checkbox array is 'chkbx_ary' then it's failing. I want the name to be 'chkbx_ary' because I want to access this array at server side. Though one may not require to see php part but I'm still pasting...
14
7029
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 way to automatically uncheck these controls by writing either a macro or module using VBA or any other method. The idea is that the user, with limited access rights and technical know how, opens Access and just run a macro or click something to...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.