Results 1 to 7 of 7

Thread: Form Validation

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    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

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    anyone?

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    In your .js file:

    Code:
    function validate(obj, message) {
    	if (obj.value == "") {
    		alert(message);
    		obj.focus();
    		return false;
    	}
    	return true;
    }
    Last edited by axion_sa; May 28th, 2003 at 12:41 PM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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");">

  5. #5
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    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?)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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.

  7. #7
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Much better that way IMO - less code, less irritation (on both your & the visitors' sides), cleaner & more efficient really.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width