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? -
-
<div id="menu1" class=hide>
-
-
<div id="col1">
-
<input type="checkbox" name="Topic" value="_topic1" />topic 1 </div>
-
<div id="col2">
-
<input type="checkbox" name="Topic" value="_topic2" />topic 2 </div>
-
-
<div id="exit"><img src="/img/exit.gif" onclick="uncheck('menu1')" /></div>
-
</div>
-
-
<div id="menu2" class=hide>
-
-
<div id="col1">
-
<input type="checkbox" name="Topic" value="_topic3" />topic 3 </div>
-
<div id="col2">
-
<input type="checkbox" name="Topic" value="_topic4" />topic 4 </div>
-
-
<div id="exit"><img src="/img/exit.gif" onclick="uncheck('menu2')" /></div>
-
-
</div>
-
-
<div id="col1"> // always visable.
-
<div><input type="checkbox" name="Topic" value="_main1" /> main 1</div>
-
<div><input type="checkbox" name="Topic" value="_main2" /> main 2 </div>
-
<div><input type="checkbox" name="Topic" value="_main3" /> main 3 </div>
-
</div>
-
-
-html -
-
function uncheck()
-
{
-
document.getElementById("Topic").checked=false
-
}
-
-
/// or ////
-
-
function uncheck2(formname,checkname,state){
-
var checkboxes=eval("document.forms."+formname+"."+checkname)
-
for (cb=0;cb<checkboxes.length;cb++)
-
checkboxes[cb].checked=state
-
}
-
-
- javascript
12 4023
Heya, Swebster.
Why is there an eval() in this line? -
var checkboxes=eval("document.forms."+formname+"."+checkname)
-
This will work just as well, and more efficiently, to boot: -
var checkboxes = document.forms[formname][checkname];
-
But more importantly, document.forms[formname][checkname] only represents a singe element.
You will want to use getElementsByTagName().
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? -
< onclick="uncheck2('menu1')"
-
- html -
document.getElementsByTagName("div").checked=false
-
- javascript
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 -
function uncheck() {
-
var ins = document.getElementsByTagName('input');
-
for (var i=0; i<ins.length; i++) {
-
if (ins[i].getAttribute('id') == 'menu1') ins[i].checked =
-
false;
-
}
-
}
-
-
- javascript -
-
<div id="menu1" class=hide>
-
-
<div id="col1">
-
<input type="checkbox" name="Topic" value="_topic1" />topic 1 </div>
-
<div id="col2">
-
<input type="checkbox" name="Topic" value="_topic2" />topic 2 </div>
-
-
<div id="exit"><img src="/img/exit.gif" onclick="uncheck()" /></div>
-
</div>
-
-
<div id="menu2" class=hide>
-
-
<div id="col1">
-
<input type="checkbox" name="Topic" value="_topic3" />topic 3 </div>
-
<div id="col2">
-
<input type="checkbox" name="Topic" value="_topic4" />topic 4 </div>
-
-
<div id="exit"><img src="/img/exit.gif" onclick="uncheck()" /></div>
-
-
</div>
-
-
<div id="col1"> // always visable.
-
<div><input type="checkbox" name="Topic" value="_main1" /> main 1</div>
-
<div><input type="checkbox" name="Topic" value="_main2" /> main 2 </div>
-
<div><input type="checkbox" name="Topic" value="_main3" /> main 3 </div>
-
</div>
-
-
-
- html
Heya, Swebster.
Each Element has the getElementsByTagName() method: -
var inputs = document.getElementById('divId').getElementsByTagName('input');
-
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? -
-
function checkall(formname,checkname,state){
-
var checkboxes=eval("document.forms."+formname+"."+checkname)
-
for (cb=0;cb<checkboxes.length;cb++)
-
{
-
var obj = checkboxes[cb];
-
if(obj.parentNode.parentNode.className!='hide')
-
{
-
obj.checked=state;
-
}
-
}
-
}
-
- javascript
[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. -
-
function resetCheckkboxes() {
-
var inputs = document.getElementsById('divId').getElementsByTagName('input');
-
for (var i=0; i<inputs.length; i++)
-
{
-
var obj = inputs[i];
-
if(obj.checkbox!='false')
-
{
-
obj.checked='false';
-
}
-
}
-
}
-
- javascript
Heya, Swebster.
Each Element has the getElementsByTagName() method: -
var inputs = document.getElementById('divId').getElementsByTagName('input');
-
This returns an error;
Object doesn't support this property or method. -
function resetCheckboxes() {
-
var inputs = document.getElementsById('divId').getElementsByTagName('input');
-
for (var i=0; i<inputs.length; i++)
-
{
-
var obj = inputs[i];
-
if(obj.checkbox!='false')
-
{
-
obj.checked='false';
-
}
-
}
-
}
-
-
- javascript
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.
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.
Check that you have a div with the ID that you're using.
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.. -
function unselect(theid) {
-
var inputs = document.getElementById(theid).getElementsByTagName('input');
-
for (var i=0; i<inputs.length ; i++)
-
{
-
var obj = inputs[i];
-
if(inputs[i].type == "checkbox") {
-
inputs[i].checked=false;
-
}
-
}
-
}
-
-javascript
Glad to hear you got it working and thanks for posting the solution.
Post again if you have any more queries.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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)...
|
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....
|
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>
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |