I am trying to validate few textboxes in a form before doing other functionality in code behind so I got :
var validForm; // **If i set it there to true it will always be true**
$('#Form :input').each(function () {
var id = this.id;
var value = this.value;
var isMatch = id.substring(0, 4) == "txt_";
if (isMatch == true) {
if (($.trim(value) == 0 ) {
alert("invalid " + id);
valid = false;
} // **if I include a else here it will not be valid as it is foreach loop**
}
});
if (validForm == true) {
$.ajax({
type: "POST",
url: "Form.aspx/Print",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d == 'Success') {
}
}
});
}
if I do an else statement in foreach loop and set validForm
variable to true it will not work as say the last textbox is valid and rest invalid then it will set my variable to true (see code comments).
On the other hand, if I assign validForm
a true at the begining then it will always be true(see code comments).
any ideas of how to overcome this issue?