Classic ASP - Submit Form when user uses Enter Key

Hi Experts,

I've come a long way in scripting and classic ASP, but this one thing is eluding me quite nicely and I can't seem to find exactly what I need and what would work for me.

My web form is just that a standard HTML form that calls an asp page for validation.  Everything works great if you mouse click the submit button, but if you try to submit the form by clicking enter... no luck.

Here's the catch:  The page has 3 forms on it... Each form has it's own set of submit buttons... so when I click enter... I'm actually submitting the 2nd of the 3 forms called upon.... not the form where the user just typed in values.

So.. I gues what I'm asking is how do I set it up so that when a user hits the ENTER key, the form he is currently in gets submitted?  The form he is currently in will be the one where he's actually filling in text input boxes.

Setup: IIS 6 on 2k3 ASP scripts & executables
98% of scripts written if VBScript
2% of scripts are javascript

Appreciate the help!
LVL 2
RanidaeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Om PrakashCommented:
Please check the following example:
<SCRIPT LANGUAGE="JavaScript">
function Login()
{
if (document.login.username.value =="")
	{ 
		alert("Login Invalid - try again."); 
	}
}
// End -->
</SCRIPT>

<form name="login" onSubmit="Login(); return false;" action="#">
  Username <input type="text" name="username"><br/>
  <input type="submit" value="Login">
</form>

Open in new window

0
RanidaeAuthor Commented:
K.. when I click enter, it submits, but it doesn't gather all the fields in the form, only the one field.  How does this get modified to cause  all input fields to be submitted along with the "username" field.
0
Om PrakashCommented:
Above example is only for one field. you can include all the fields you need.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

scrathcyboyCommented:
Maybe a simpler way with these 3 forms is to block ENTER from submitting any form.  That way the user has to click on one or the other of the submit buttons -- a normal expectation for most users.  To see how to block enter from submitting any form, look at these --

http://www.itechies.net/dev/code-samples-tutorials-and-examples/Html/details_faq-sbres_id-30.htm
http://www.cs.tut.fi/~jkorpela/forms/enter.html
http://www.dynamicdrive.com/forums/showthread.php?t=34561
http://www.irt.org/script/1693.htm
http://www.arraystudio.com/as-workshop/disable-form-submit-on-enter-keypress.html

They all show different ways of doing the same thing.
0
BanthorCommented:
ASP has completed it's part of the process before the browser starts to render.
This is an HTML issue.
The behavior you are trying to accomplish is what should be happening normally. IF there is only one button as a type="submit"
if you have other buttons in a form they should be either type="button" or type="reset"
if your user is entering data in a textarea, the Enter Key behavior is modified. If you want a user to right a several lines of data and then use enter to post the form. change all textareas to <input type="text"
you can then set the attribute lines="3" without affecting the beahvior of the enter key
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BanthorCommented:
Lines is not correct, might have to do that with style.
http://www.w3.org/TR/html401/interact/forms.html
 
0
RanidaeAuthor Commented:
Well, I found an answer outside of the forum:

Java script at the top of the page (not in the <head>)
<SCRIPT LANGUAGE="JavaScript">
function entsub(myform) {
  if (window.event && window.event.keyCode == 13)
    myform.submit();
  else
    return true;}
</SCRIPT>

and in every form element (type="text" type="radio" ... ) I add: onkeypress="return entsub(this.form)"

and presto... fixed all my problems.

Thanks all for your contributions.

0
RanidaeAuthor Commented:
A solution was independently found outside of this posting.  Points assigned according to the lvl of learning provided by each expert.
0
scrathcyboyCommented:
any (or most) of us could have told you the javascript check on CR -- but you wanted an ASP solution, as the question was asked.
0
RanidaeAuthor Commented:
My appologies for not broadening the options.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.