Jquery radio button validation

Discussion in 'jQuery' started by danramosd, Mar 4, 2010.

  1. #1
    I have a php script that generates a form of all radio button types. The form consists of ratings questions (1-10 values), true or false(2 values), and another type that has 4 values. Since the form displayed is different based on the user i wanted to create a javascript (im using jquery) to validate the form dynamically also so i dont have to check for each value individually. I just need to make sure that each radio group has a value. Each radio button has a class of .input but each radio group obviously has a different name and different values. So far i can loop through, and alert the value of the checked radio buttons:
    
    $('.input').each(function(){			
    	if($(this).is(":radio:checked")) {
    			alert("attribute"+$(this).attr('name')+" value="+$(this).val()); 
    		}
    		
    		});
    	
    
    Code (markup):
    I'm not really sure to go from here. I need to check if there are any null values in any null groups and display an error if there is.
     
    Last edited: Mar 4, 2010
    danramosd, Mar 4, 2010 IP
  2. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #2
    On the first line, you have $('.input'), but this means you are selecting all elements, which have "input" class set. Try to make it $('input') (without the dot)... Maybe there will be problem with the rest of the script too, but try this first.
     
    Houdas, Mar 5, 2010 IP