Reputation: 972
I am validating my form using jQuery as below:
$(document).ready(function(){
$('input[name=subdomain]').keyup(subdomain_check);
$('input[name=password]').keyup(password_strenght);
$('input[name=c_password]').keyup(password_check);
$('input[name=email]').keyup(email_check);
$("#install").submit(function(e){
if(!subdomain_check() || !password_strenght() || !password_check() || !email_check()) {
e.preventDefault();
}
});
});
Now the issue here is how do I prevent the form from submission if the rules are not met? When I click the submit button nothing should happen.
Thanks
Here is the whole script
: http://pastie.org/8812743
Upvotes: 0
Views: 86
Reputation: 11693
Use following way:
<input type="submit" value="Delete" onClick="return funEverythingOK();" />
In funEverythingOK(),Check for everything is filled well,Here in this function,Return true ,if everything is ok,else false
Upvotes: 0
Reputation: 2891
$("#install").submit(function(e){
if ($("#subdomain_check").valid() == true &&
$("#password_strenght").valid() == true &&
$("#email_check").valid() == true)
{
$( "#form_id" ).submit();
return true;
}
else
{
return false;
}
});
Upvotes: 0
Reputation: 290
$(formSelector).on('submit', function(){
return subdomain_check() && password_strenght() && password_check() && email_check();
});
Upvotes: 1