Mark validation errors

Mark validation errors

I faced a problem today that I needed to give controls, that failed validation, an error class.
I found this little gem online:



function WebForm_OnSubmit() {
var errorControls = new Array();
if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
for (var i in Page_Validators) {
try {
var control = document.getElementById(Page_Validators[i].controltovalidate);
if (!Page_Validators[i].isvalid) {
errorControls[errorControls.length] = control;
}
control.className = "";
} catch (e) { }
}
for (var i in errorControls) {
errorControls[i].className = "errorClass";
}
return false;
}
return true;
}

Where “errorClass” is the class you want to give your controls.

Thank you aspforums.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.