ucohockey
asked on
form validation
I have a form that I'm trying to validate on click of button. I have a password and a checkbox and would like to display a java alert when they are not selected. For example if the passcode is not field in I want to display a java alert saying please fill enter passcode, and then if the checkbox is not checked I want a java alert to say please check the box.
<script type="text/javascript">
$(document).ready(function() {
$('.connectButton').click(function(){
if($('#check1').is(':checked')){
return true;
} else{
swal("Oops...", "Please review and then click the Terms and Conditions check box!", "error");
return false;
}
if ($('.pcodeHome').val() === '') {
alert("Oops...", "Please enter passcode!", "error");
return false;
}
return: true;
}
$('.connectButton').fadeOut(function(){
$('.package-wrapper').hide();
$('#progress').fadeIn();
});
});
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
As you can see, if the checkbox is checked you return from the function and skin further validation. What you need to do instead is to check if the checkbox is not checked but continue to validate the rest, like this:Open in new window