Reputation: 10412
I am using jquery form validation to alert the user if the form is not valid.
if (!$(Form1).valid()) {
alert("invalid form")
}
is there a way to force the form to be invalid in javascript.
for example I have a textbox and if it's value is "123" I want the form to become invalid.
something like this:
if($("#TextBox1").val()=="123"){
$(Form1).valid() = false;
}
Upvotes: 1
Views: 957
Reputation: 1422
you can set the value (true or false) to a variable
if($("#TextBox1").val()=="123"){
var responce1 = false;
}
if($("#TextBox2").val()=="abc"){
var responce2 = false;
}
and at last you can check as
var resultresponce=responce2 && responce1;
and lastly you need to check if the value of resultresponce
is true... if so you can submit the form or else not..
if(resultresponce)
{
$(form).submit();
}
Upvotes: 1
Reputation: 1506
What you can do to invalidate the Form is to disable the connected submit button, so the user can't submit it. See: jQuery disable/enable submit button
Upvotes: 0
Reputation: 3540
You should try to just use a if statement for this one. Something like:
if ($("#el").val() == "123") {
// Do something or nothing here.
} else if (!$(Form1).valid()) {
alert("invalid form")
} else {
// All correct
}
What philnate says should also work fine. It's more what you want to happen.
Upvotes: 0