Checking if radio is selected causes false returned
Hi. I have written a little validation script to check a few fields in a recent project.
The last part, which checks if a radio input group has a checked element is failing. For some reason it is returning false after it has run once.
- if (!$("input[name='print-options']").is(':checked')) {
$('.prompt-radio').show();
required = false;
} else {
$('.prompt-radio').hide();
}
Can anyone see what the mistake is?
Here is the full script.
- $('form').submit(function(e) {
$('.required-prompt', this).remove();
$('.required', this).each(function() {
if( !$(this).val() ) {
$(this).after(prompt);
required = false;
} else {
$('.required-prompt', this).remove();
}
});
$('.email', this).each(function() {
if( !email.test($(this).val()) ) {
$(this).after(promptEmail);
required = false;
} else {
$('.required-prompt', this).remove();
}
});
if (!$("input[name='print-options']").is(':checked')) {
$('.prompt-radio').show();
required = false;
} else {
$('.prompt-radio').hide();
}
return required;
});