-
Form Validation
Hello All,
I have a pretty large ASP app (30 pages). On this app, there are many text boxes, etc. I would like to validate all of these, but to do individual javascript functions on each page seems silly. Logically, I would like to use an external js file and just pass all of the text boxes there for validation. BUt I am a little confused on how to implement that. Ideas?
Brian
-
-
In your .js file:
Code:
function validate(obj, message) {
if (obj.value == "") {
alert(message);
obj.focus();
return false;
}
return true;
}
-
OK, where would you call that (onBlur of the text box, or somwhere else. Here is what I have so far:
Code:
<input type="text" name="txtotherMake" size="20" maxlength="20" onBlur="validate "document.wStations.otherMake.value", "you messed up");">
-
I usually do the validation when they're submitting a page - it annoys the user less (the user being me - page has to be tested, don't it?)
-
yeah it is annoying to get a pop up message everytime you leave a text box without filling it out. The only issue is that I am already calling a function when the user submits the form, but I guess that I could place the code in that function.
-
Much better that way IMO - less code, less irritation (on both your & the visitors' sides), cleaner & more efficient really.