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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    radio index question

    So if radio buttons have the same name and have to use form.name[x], what do I do if I want to use an index for the input too? alert(form[x][y].value) does not work. Any suggestions?

  • #2
    Senior Coder
    Join Date
    Jul 2002
    Posts
    1,628
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why would your radio buttons have the same names in one form?

    Moderator: General web building

    Get out from under them, resist and multiply.
    Get out from under precipice and see the sky.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Radio buttons SHOULD have the same name, they are used for a single response out of multiple choices (like a multiple choice quiz).

    Not sure what you mean by "use an index for the input". Can you explain?

    Perhaps...

    var radios = document.forms[0].yourradioname;
    var radlen = radios.length;
    for(var i = 0; i < radlength; i++) {
    alert(radios[i].checked);
    }



    What exactly are you trying to do?
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    Well lets say I have a form named G and several inputs.

    <FORM name="G">
    <INPUT type="checkbox" checked>Choice A<BR>
    <INPUT type="checkbox">Choice B
    </FORM>

    I normally use in a script activated by a button to read the values of these checkboxes. Not by their names (not assigned), but their index. Such as

    if (G[1].checked){alert("Choice B was selected")}

    But then radio buttons need to use an index too.

    <FORM name="G">
    <INPUT type="radio" name="gre1">No<BR>
    <INPUT type="radio" name="gre1">Yes<BR>
    </FORM>

    Well, I guess each input works independently by themselves in their indexes regardless of wheather G[0] and G[1] have the same name or not. So names can be indexed, but the form index of each input works alone the same way as checkboxes. Is this right so far?

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The index doesnt care what it refers to.. just use the index and it will work...

    if you have
    radio
    radio
    check
    radio
    check
    check

    on you form indices 2,4,5 will be checks and 0,1,3 radios
    doesnt matter of they are text boxes either..
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.


  •  

    Posting Permissions

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