www.webdeveloper.com
Results 1 to 5 of 5

Thread: How can I validate a radio button?

  1. #1
    Join Date
    Nov 2002
    Location
    Tucson, AZ
    Posts
    12

    How can I validate a radio button?

    I would like to make sure the user selects a radio button. (as in a Yes, No set) By default none of the buttons are selected. if (strMedical == '') or if (strMedical == 'No'), etc. doesn’t respond. Is there a way to check if a button in a set has been selected and pop up a message if none of the buttons were selected?

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    Radio buttons have a "checked" parameter. If the button is selected, it's "checked" parameter is true, otherwise it is false. So use the following syntax:

    if (!document.formName.strMedical.checked) // not checked

  3. #3
    Join Date
    Nov 2002
    Location
    Tucson, AZ
    Posts
    12

    radio vrs. checkbox

    Thanks, Gil. I was able to get that working for checkboxes, but it doesn't seem to work on radio buttons. It returns as unchecked no matter what. Is there a different paramiter that is used by radio buttons?

  4. #4
    Join Date
    Nov 2002
    Posts
    4,473
    Yes, a radio button has the attribute "checked". See http://developer.netscape.com/docs/m...o.htm#1193294.

    Is the radio button really in an array or something?

    Post the relevant parts of the form. Better yet, a link to your page.

  5. #5
    Join Date
    Nov 2002
    Location
    Tucson, AZ
    Posts
    12

    Yes, it's an array

    Yes, you were right. When there's more than one button in a set it's an array. I just added the [0] and [1] at the end and now I can detect Yes and No selections. Thanks for the link the to javascript docs. That will be a big help.

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