Better alternatives to know whether a control is valid in javascript?
Posted
by
Anthony
on Stack Overflow
See other posts from Stack Overflow
or by Anthony
Published on 2012-04-13T05:25:46Z
Indexed on
2012/04/13
5:28 UTC
Read the original article
Hit count: 173
I want to know whether a control is valid or not in javascript. Is there a direct client side API available in Asp.Net which can tell me whether a control is valid or not?
Eg. If I have 2 validators attached to a textbox, I need a function that can tell me whether the textbox is valid or not. If even 1 validator is not valid then it should return false.
I can't seem to find a function that can give me this. Here is a little helper that I wrote which does the job but is inefficient:
function isControlValid(control) {
for (i = 0; i < Page_Validators.length; i++) {
var validator = Page_Validators[i];
var controlId = validator.controltovalidate;
if ($(control).attr('id') == controlId && validator.isvalid == false) {
return false;
}
}
return true;
}
Anybody has any better alternatives?
© Stack Overflow or respective owner