What I'm trying to do here is have a form validation. I have 3 element here, a,b and c.
What I need to do is:
Edit: Just to correct my question
If a != 0 || a != '' validation_holder = 1;
else, if var a has value greater than zero, compare the value of b and c, c should not greater than b
if no errors submit the form.
I'm trying to do this in nested if else.
And here's what I have right now. http://jsfiddle.net/jWL9s/2
Any help will appreciate.
<form action="" method="post" id="register_form" name="register_form">
PO<input type="text" id="a" value="0"/><br/>
Remain<input type="text" id="b" value="10"/><br/>
PR<input type="text" id="c" value="5"/><br/>
<span class="alert"></span>
<input name="edt_submit" type="submit" value="Edit">
</form>
jQuery(function($) {
var validation_holder;
$("form#register_form input[name='edt_submit']").click(function() {
var validation_holder = 0;
var a = $("form#register_form input[id='a']").val();
var b = $("form#register_form input[id='b']").val();
var c = $("form#register_form input[id='c']").val();
if(a != 0 && a != '') {
$("span.alert").html("You Cannot edit").addClass('validate');
validation_holder = 1;
} else {
if( b > c ) {
$("span.alert").html("Value is Greater than").addClass('validate');
validation_holder = 1;
} else {
$("span.alert").html("");
}
}
if(validation_holder == 1) { // if have a field is blank, return false
$("p.validate_msg").slideDown("fast");
return false;
} validation_holder = 0; // else return true
/* validation End */
}); // click End
}); // jQuery End
if( c > b ) {is a string comparison.if..elseworks differently in jQuery?$("form#register_form input[id='a']")is hugely less efficient than: $('#a').