Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable the enter key on asp

Status
Not open for further replies.

BonitaRobinson

IS-IT--Management
Jun 3, 2002
6
US
Hi :)

How do I disable the enter key on an asp form that posts to a MS Access DB. The input fields are text boxes.

Any advice is greatly appreciated.

Bonita
 
If you don't want the "enter characters" in the data, you can =replace(text,chr(13)&chr(10)," ")

Or you can try some client side JavaScript/VBScript to listen the Enter key with OnKeyPress event of an object, but it's not 100% guaranteed.
 
Thanks Denoxis

Actually, what I want to do is not let the form submit if the user hits the enter key. Right now all the fields are text fields. Only a few of them are required fields. The form is used to post benchmark testing results. There are many many fields on this form. I know I can make all the fields required with a min and max field size. I'm pretty sure this will fix the submission problem to DB by just hitting the enter key. I was hoping there was an easier fix :)
 
Firstly, there is no way todo this in ASP, see full explanation in the ASP FAQ (2nd one linked in my sig)

Ok, so you could do this in Javascript in two differant ways, either
a) put a keydown event in every input and call a function to check if it is the enter key. If it is the enter key return false, if it isn't return true. returning false will in effect stop that enter key from being registered by the form, while returning true will still allow the rest of the characters to be registered.
b) create a form validation function that makes sure all the forms have their minimum number of characters, use the onSubmit event in the form tag to call the function. Return false if you don't want it to submit, return true if you do want it to submit. Call the function like so:
Code:
<form method=&quot;POST&quot; action=&quot;whatever.asp&quot; onSubmit=&quot;return validateFunction();&quot;>
The return inside the onSubmit is what causes it to cancel or continue the submit based on the return value of the validateFunction.

-Tarwn ________________________________________________________________________________
Sometimes it is how you ask the question: faq333-2924
Many ASP questions have already been answered, please check faq333-3048 and use the search tool before posting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top