tags:

views:

29

answers:

1
rules: {
firstname: "required",
lastname: "required",
birthdate: {
    date: true,
    required: true,
    minimumAge: true
}, 
consent: {
  required: function(element) {
   return getAge($("#birthdate").val()) < 18;
   $("#consent").show();
  }
}
});
$("#consent").hide();

I want to show a check box for consent if the age of the user is below 18, From the above code why isn't working?

+1  A: 
return getAge($("#birthdate").val()) < 18;

^ You're returning a boolean, and that function is done executing so it doesn't process the $('#consent').show() .. you probably meant to wrap this in an if statement:

if ( getAge( $('#birthdate').val() ) < 18 ) {
   $('#consent').show();
}

Or reverse the < to >, however it works out.

meder
Your first answer will work, but reversing the < to >, will not work. It will just return the opposite of the code in the OP.
Marius
yeah, I was initially confused on what he wanted so if he wanted it the other way and I misread all he had to do was switch the operator.
meder