Click to See Complete Forum and Search --> : Need help with this select all checkboxes code...


jeff_borden
03-12-2003, 11:15 AM
I can't seem to get this code to work quite right.

------------------------------
the function (works fine)
------------------------------
<script language=javascript>
<!--
function SomeJSFunction(oDiv,doit){
var curobj = eval(oDiv+'.children')
i=0
while(i<curobj.length){
if(curobj[i].type=="checkbox"){
curobj[i].checked=doit
}
i++
}
}
-->
</script>
------------------------------------

when i use the function with the checkboxes nested within only a <DIV> tag... it works correctly.
Unfortunately the code i need to apply this to uses tables and it doesn't work properly.

--------------
Works
--------------
<div ID='Div3'>
<input type=checkbox name=selected_mail value='checkall' onclick=SomeJSFunction(this.parentElement.id,this.checked)>
<input type=checkbox name=selected_mail[] value=132><input type=checkbox name=selected_mail[] value=131><input type=checkbox name=selected_mail[] value=130><input type=checkbox name=selected_mail[] value=129><input type=checkbox name=selected_mail[] value=128><input type=checkbox name=selected_mail[] value=127><input type=checkbox name=selected_mail[] value=126>
</div>

---------------------------
Code I need to work
---------------------------

<div ID='Div3'>
<table>
<TR>
<td align=center>
<input type=checkbox name=selected_mail value='checkall' onclick=SomeJSFunction(this.parentElement.id,this.checked)></td>
</TR>
<TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr><TR><td align=center><input type=checkbox name=selected_mail value=></td></tr> </table>
</div>

------------------

Any ideas???? thx

gil davis
03-12-2003, 11:55 AM
Originally posted by jeff_borden
Works
--------------
<div ID='Div3'>
<input type=checkbox name=selected_mail value='checkall' onclick=SomeJSFunction(this.parentElement.id,this.checked)>
...
---------------------------
Code I need to work
---------------------------
<div ID='Div3'>
<table>
<TR>
<td align=center>
<input type=checkbox name=selected_mail value='checkall' onclick=SomeJSFunction(this.parentElement.id,this.checked)></td>
...
Any ideas???? thx In the working case, the parentElement is the DIV, and it has an ID. In the non-working case, the parentElement is the TD, and it has no ID (it also does not contain the rest of the form elements).

If you would use a FORM tag (like you are supposed to), then you could get to all the form elements using "this.form" - regardless of the intervening HTML objects.

jeff_borden
03-12-2003, 12:04 PM
So do you think i would jsut have to change the check all check box to something like this:

<input type=checkbox name=selected_mail[] value='checkall' onclick=SomeJSFunction(this.form.id,this.checked)>

Do you think that would work?