0

I'm currently having a headache trying to figure this one out.

I have a set of radiobuttons where three radiobuttons belongs to a question. It's basically a survey where you are able to choose answer A, B or C per question. What I want to do is to make sure that the user has selected either A, B or C for every group of radiobuttons. This should prevent the form submitting when there's an unanswered question.

So basically the layout is as follows:

Question: What day is it today?                       [A] [B] [C]
          A) Monday  B) Sunday C) Wedensday           [ ] [ ] [ ]

I have made sure that each of the radiobuttons has the same unique id (well, the name attribute in this case) as their parent td's ID attribute, to be able to "group" radiobuttons that way.

Has anyone done this before and are willing to share how you did it? :-) Would be greatly appreciated!

Thanks in advance,

Bo

bomortensen
  • 3,346
  • 10
  • 53
  • 74
  • possible duplicate of [Validation of radio button group using jQuery validation plugin](http://stackoverflow.com/questions/277589/validation-of-radio-button-group-using-jquery-validation-plugin) – mcgrailm Jan 11 '12 at 16:43

2 Answers2

1

To ensure a radio button is selected for a group using jquery:

if( $('input[name=groupName]').is(':checked') ){//do something}.

From this post: Radio button selected?.

this is a good tutorial for details on jquery form validation techniques.

http://webcloud.se/log/Form-validation-with-jQuery-from-scratch/

Community
  • 1
  • 1
jamesTheProgrammer
  • 1,747
  • 4
  • 22
  • 34
0

Use jQuery validate - it's all built in.

The code would then just be:

$("FORM").validate();

You can obviously specify further settings if required, such as error messages and what values to validate.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339