It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Validate radio button with jquery?

Validate radio button with jquery?

Postby wzshop on Wed Mar 09, 2011 11:00 pm

Hi there,

I am totally new to jquery and did manage to design a form and check fields on values (with a little help;)) with jquery. Now i also have 2 radio button options (gender), and at least 1 need to be checked. So i would like to validate this too before the form will be sent.

Here is my validation now, without the radio funtion:
Code: Select all
  //ckeck if inputs aren't empty
      var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
        var fields = $('#first_step input[type=text], #first_step textarea');
        var error = 0;
        fields.each(function(){
            var value = $(this).val();
              if( value.length<1 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='Email' && !emailPattern.test(value) ) ) {
                $(this).addClass('error');
                     
                error++;
            } else {
                $(this).addClass('valid');
            }
        }); 

      //check radio buttons
Here my radio buttons check

//Step 2 of form

//send form
      



Does anybody know how to check if someone has filled in their gender? My radio group name ="gender". Furthermore if no radio button has been selected I would (really) like that the text within the spans, below, lights up red:

Code: Select all
<div><label><span>Male</span><input type="radio" name="gender" id="Male" /><span>Female</span><input type="radio" name="gender" id="Female" /></label></div>


If someone could help me out with this, u would really make my day! Tried a lot, but can't figure it out..
Thanks a lot for your time.
Kind regards,
Robbert
wzshop
 
Posts: 1
Joined: Wed Mar 09, 2011 10:59 pm

Who is online

Users browsing this forum: No registered users and 10 guests