Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkbox checking...

    I have a form that produces a few checkboxes via a server side
    script. Once on the page, the source looks like this...

    <tr>
    <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>
    </tr>
    <tr>
    <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>
    </tr>

    ...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;
    alert(myOpt);
    }

    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!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    you passed value is a string not a decimal number.Make it a number.

    var myOpt=document.frmNew.view[Number(opt)-1].value;
    Last edited by Kor; 05-02-2006 at 03:41 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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) {
    alert('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?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •