View Full Version : Checkbox checking...

05-02-2006, 02:30 PM
I have a form that produces a few checkboxes via a server side
script. Once on the page, the source looks like this...

<td><input type="checkbox" name="access" value="1" checked /></td>
<td><input type="checkbox" name="view" value="1" checked
onclick="AM_MenuSelection(this.value)" /></td>
<td><input type="checkbox" name="access" value="2" checked /></td>
<td><input type="checkbox" name="view" value="2" checked
onclick="AM_MenuSelection(this.value)" /></td>

...what I'm trying to do is pass through the value of the checkbox
ticked through to a function. This function will then, depending on
whether the box is ticked or not, untick the access# checkbox.

I can pass the number through to my function, but I'm having
difficulty trying to reference the actual checkbox from the script.
This is what I've got so far...

function AM_MenuSelection(opt) {
var myOpt=document.frmNew.view[opt].value;

As you can see, I can reference the value of the object, but need to
be able to access the related access# object.

Eeeeek, help!

05-02-2006, 02:39 PM
you passed value is a string not a decimal number.Make it a number.

var myOpt=document.frmNew.view[Number(opt)-1].value;

05-02-2006, 02:45 PM
Cheers, although it didn't really make a difference here.

I used the following code...

var myOpt=document.frmNew.view[Number(opt)].value;
if(document.frmNew.access[Number(opt)].checked) {

...so I want to now check the see if the value of the access# checkbox is checked or not. But when I use this, regardless of whether the box is checked or not, it keeps display the alert text.

Any ideas?

05-02-2006, 03:04 PM
var myOpt=document.frmNew.view[Number(opt)-1].value;

your elements have the same name, so that they are elements of a collection (much appropiate with an array). Or in array elements are counted starting from 0