www.webdeveloper.com
Results 1 to 4 of 4

Thread: radio button validation

  1. #1
    Join Date
    May 2011
    Posts
    46

    radio button validation

    I have an mysql array with several radio buttons,

    <INPUT name="bookout" id="bookout" type="radio" class="formslova" value='value1'>
    <INPUT name="bookout" id="bookout" type="radio" class="formslova" value='value2'>
    <INPUT name="bookout" id="bookout" type="radio" class="formslova" value='value3'>


    I want to make a button validation:

    if (document.getElementById("bookout").checked==false) {
    alert('error');

    For some reason when I have more that one button in the array only the first counts, meaning only when first is clicked is the button validation checked=true.

  2. #2
    Join Date
    May 2011
    Posts
    46
    I am sorry, wrong forum.

  3. #3
    Join Date
    May 2011
    Posts
    1
    all your radio button has same id, which is incorrect, that is why your validation fails.
    you have to change the id for your radio button and that should work

  4. #4
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    Yup -- change or remove the ID on the buttons. It'll probably easiest to validate using a reference to the form:

    HTML Code:
    var form = document.getElementById('form_id');
    if (!form.radio_group_name) {
      // alert the user somehow
    }
    ... or something along those lines. And remember that client-side validation is not sufficient in itself! Check everything server-side as well.
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles