Click to See Complete Forum and Search --> : checkbox setting


kopite
04-04-2003, 02:24 PM
Hi,

I am trying to set the boolean value on a checkbox element, such as below by accessing it through the desired table:

document.getElementById("mytable").checkbox[index].checked = true;

but this does not work, I can set the value though on the checkbox when I write it like this, but I want to avoid this due to obvious limitations:

myform.elements[index].checked = true;

Please help.

thanks.

Nedals
04-04-2003, 02:58 PM
document.getElementById('checkboxName').checked = true;

kopite
04-06-2003, 04:31 AM
I do not know the name of the checkbox element - only know the index so can not apply that solution.

I only know the names of the form and table in which the checkbox elements reside.

khalidali63
04-06-2003, 08:15 AM
There are multiple ways you can get this done.
1.use getElementById

var obj = document.getElementById("tableID");
var cbees = obj.getElementsByTagName("input");
and now you can loop through and set status.

2.Name all the check boxes when you create them the same this will create an
array of all Checkboxes and then you can access it using

document.formName.cbArrayName[index].checked...

or you can loop through form elements and check for type of the element if its type=="checkbox" then sent it to true.

Hope this helps

Cheers

Khalid