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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form element id question

    I have a form element that is a radio and mutually exclusive of 4 others. All 4 have the name 'radio'. I am using JS to calculate the value of the selected radio as well as other elements on the form.

    When the form is submitted I need to know which one of the 4 radios was selected so that I can insert the proper info into a database. Since they all have the same name to allow them to be mutually exclusive the post just has the one name. I have been comparing the value 'radio' with the value of other variables on the page to determine which of the four was selected.

    This works great until I have radios with the same values. Is there another way to identify radios while still leaving them mutually exclusive?

  • #2
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just solved my own question but wanted to post it if anyone else has a similar need:

    I left the radio button name alone and simply made a hidden input type and used JS onblur at each radio button to enter a distict value that can be retrieved on the post.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    An example of radio button polling to check which one has been selected:-

    (buttons have same name, different values)

    <form name = "myform">
    1<input type = "radio" name = "rad1" value = "1">
    2<input type = "radio" name = "rad1" value = "2">
    3<input type = "radio" name = "rad1" value = "3">
    4<input type = "radio" name = "rad1" value = "4">
    <input type = "button" value = "Click here to rotate the selected image" onclick = "rotate()">
    </form>

    <<script type = "text/javascript">
    function rotate() {
    for (var i =0; i < document.myform.rad1.length; i++) {
    if (document.myform.rad1[i].checked) {
    var selected = document.myform.rad1[i].value;
    }
    }
    if (!selected) {
    alert ("You must select an image to rotate! ");
    return false;
    }
    }
    </script>

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 06-17-2008 at 09:37 AM. Reason: Typo noted


  •  

    Posting Permissions

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