Click to See Complete Forum and Search --> : How do I make a field required?


gcook1
08-29-2005, 09:54 AM
This is probably simpler than I imagine....but I can't seem to find the answer.

I have a form and want to make several fields required. I'm not validating or anything...just requiring the user to enter SOMETHING. How do I do that?

Thanks for your help!

minority
08-29-2005, 09:58 AM
two ways the first since yu are in the asp forum is
when the submit page is clicked you check the fields to ensure there is something in them. and if not redirect them back to the form and have a sentence saying this is required.

the other option which is more what you are after is javascript based where you can have on blur or on click where it will check the fields to ensure there is something in all the fields that require input.

buntine
08-29-2005, 07:19 PM
Validation should be performed from both ends -- client and server. If you rely on JavaScript, you are alienating a certain percentage of users.

From the server-side; an ASP environment, the following will suffice:

Dim strName
strName = Request.Form("txtName")

If strName = "" Then
'| Field is empty. Notify user or redirect back to referring document.
End If

Regards.

Bullschmidt
08-31-2005, 07:48 AM
And here are some related links.

Server-side:

Server-Side Form Validation by Dianna Leech - 12/1/1999
http://www.4guysfromrolla.com/webtech/120199-1.shtml

An Email Validation Routine by Joćo Vieira - 4/11/1999
http://www.4guysfromrolla.com/webtech/041199-1.shtml
Somewhat shorter.

An Email Validation Script by Ben Durbin - 5/19/1999
http://www.4guysfromrolla.com/webtech/051999-1.shtml
Longer.

Form Handler: Some light form validation and error notification.
http://www.asp101.com/samples/form_handler.asp
Uses function to loop thru all fields in a form.
Also shows Response.Write using double double quotes:
Response.Write "<IMG SRC=""../images/check.gif"" BORDER=""0"" WIDTH=""25"" HEIGHT=""25"">"

ASP/Jscript Email Validation - 5/28/1999
http://www.4guysfromrolla.com/webtech/052899-1.shtml
Uses JavaScript run at the server.

Client-side:

Javascript Field Validations -- Client Side Scripting by Nannette Thacker - 8/19/1999
http://www.shiningstar.net/articles/articles/javascript/javascriptvalidations.asp?ID=AW

Form Validation Using Javascript - 9/19/1998
http://www.4guysfromrolla.com/webtech/091998-1.shtml
Good tips such as saving JavaScript functions in a file called DataValidation.js and including this in pages that need this.
JavaScript functions.

WebDaily: Your daily source for Web Technology Tips and Tricks! - 10/27/1998
http://www.4guysfromrolla.com/webtech/102798-1.shtml