Check Radio Buttons And Fields To Enable Link
I have a form with a lot of radio buttons and a couple of text fields. So...
Edited to amend your code:
Solution 1:
I think that this should work:
if ($('input:radio[name=pic]:checked').length && $('#email').val().length && $('#comment').val().length) {
/* activate the lightbox link */
}
else {
alert("Please ensure you've selected one of the radio buttons, and filled out the text-fields.");
}
Edited to amend your code:
html:
<form action="#" method="post">
<input type="radio" name="pic"id="pic" value="val1">
<input type="radio" name="pic"id="pic" value="val2">
<input type="radio" name="pic"id="pic" value="val3">
<input type="text" name="email"id="email" value="">
<input type="text" name="comment"id="comment" value="">
<input type="submit" value="submit" />
</form>
jQuery:
$('form').submit(
function() {
if ($('input:radio[name=pic]:checked').length && $('#email').val().length && $('#comment').val().length) { /* activate the lightbox link */
}
else {
alert("Please ensure you've selected one of the radio buttons, and filled out the text-fields.");
}
returnfalse;
});
Solution 2:
$("#link").click(function(e) {
if ($('input[name=pic]:checked').val() && $('#email').val() && $('#comment').val()) lightbox();
else e.preventDefault();
});
Solution 3:
functionchecklink() {
if ($('[name=pic]').val()) && $('#email').val() && $('#comment').val()) {
$('#linkId').hide();
} else {
$('#linkId').show()
}
then add onchange="checklink()"
to your input fields
Edit: fixed disabling as per @fehergeri comment
Post a Comment for "Check Radio Buttons And Fields To Enable Link"