SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form validation - only one checked box?

    I have a form.

    My first question is multiple choice with 4 options. All checkboxes with specific names.
    E.g. the checkboxes are name:
    agree1
    disagree1
    notsure1
    na1

    I am able to validate if none of those are clicked then to alert the user to answer at least once..
    What I need is, if two or more are clicked....HOW to tell the user to only submit one answer?

    any advice?
    Last edited by meztec; Aug 13, 2001 at 07:26.

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi meztec,

    The way to solve your problem is to use radio buttons, not checkboxes. The former element type is used when only one out x answers is valid. The latter element type is used when you want to allow 0 to X answers.

    <input type='radio' name='r1' value='agree' checked>Agree
    <input type='radio' name='r1' value='disagree'>Disagree
    <input type='radio' name='r1' value='notSure'>Not Sure
    <input type='radio' name='r1' value='na'>NA

    submission will send the selected radio button
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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