Print Page | Close Window

form validation

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5551
Printed Date: 30 March 2026 at 9:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: form validation
Posted By: simflex
Subject: form validation
Date Posted: 05 September 2003 at 10:54am

Maybe I overlooked your javascript forum but I could not find one when I browsed the "select forum" dropdown.

I have a long asp page coded to client's spec.
The problem with this page is to determine that a box is blank, the entire form is usually completed first.
They have found that this is cumbersome and frustrating so they have asked me to put a trigger or an event handler that will prevent a user from leaving some textboxes before data is entered into that text box.
I have several onSubmit() javascript codes but they don't solve the problem because the client is still dealing with having to complete entire form before finding that an error exists.
Can someone give me a link or a help on the code that prevents a user from leaving an input textbox until value is entered into that textbox, please?


Thanks for your assistance in advance.

 




Replies:
Posted By: MorningZ
Date Posted: 05 September 2003 at 11:07am

Hopefully can start you on the way

<html>
<head>
<script language="javascript">
function CheckForEmpty(obj) {
     if (trim(obj.value)=='') {
          alert('Please Complete the Field');
          return false;
     }
     return true;
}
function trim( i_strValue ) {
     return i_strValue.replace(/^[ ]*|[ ]*$/g, '');
}
</script>
</head>
<body>
<form onSubmit="alert('It is OK to post now')">
Enter Data:<br/>
<input type="text" name="Name" onBlur="return CheckForEmpty(this);"/>
<br/><br/>
<input type="submit" value="Post Form"/>
</form>
</body>
</html>



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: simflex
Date Posted: 05 September 2003 at 12:01pm

thank you very much.

It doesn't keep the cursor on that input box but atleast it gives the user a message.



Posted By: MorningZ
Date Posted: 05 September 2003 at 12:10pm

i never said "ship it" on that code.. it was just a way of getting you started... its your app, not mine  :-)... you write it

but alas... a simple addition of one line

if (trim(obj.value)=='') {
     alert('Please Complete the Field');
     obj.focus();
     return false;
}



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: simflex
Date Posted: 05 September 2003 at 12:53pm

I did add this line: obj.focus();
 and I was just coming back to advise you of that.

Thank you and by the way I didn't try to insinuate that that was a finished product; at least I hope that was not the impression I gave you Sorry if I did.

Thanks again for your help.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net