How to make an Input field recognize the enter keystroke

I've got an HTA that has 1 input box and 8 read only return boxes.  I want the 1 input box to submit the user's entry on the enter keystroke.  I know the input box has to have the onKeyDown(callsub), but what does the sub do?
LVL 12
piattndAsked:
Who is Participating?
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.

piattndAuthor Commented:
So an update on this, I got it so it recognizes the enter keystroke, now how to I tell the SUB to click the submit button if the keystroke = enter?
0
hieloCommented:
>> click the submit button if the keystroke = enter
are you trying to submit the form?
If yes, then make sure you give the form an id:
<form id="theForm">
 
and when you detect the Enter you then execute:
document.getElementById("theForm").submit()
 
If you are NOT trying to submit the form, but instead are trying to execute some onclick function on the button:
<input type="button" onclick="foo()">
 
then simply call the function directly when you detect the enter key

Open in new window

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
piattndAuthor Commented:
Thanks much, I actually had hit up a friend who helped me understand what was going on.  I appreciate the response (yours was what I was looking for)!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

RobSampsonCommented:
Hi, you can add this to you <body> tag in the HTML section:
<body onkeypress='vbs:Default_Buttons'>

and then add this in your <script> section:
Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_install.Click
      End If
End Sub


where you can change btn_install.Click to the name of the OK button control.

Regards,

Rob.
0
hieloCommented:
Hmm, that grade simply seems inappropriate. The answer was technically sound. So I "lost" 500pts for no reason. Perhaps you should read:
http://www.experts-exchange.com/help.jsp#hi504
0
piattndAuthor Commented:
My fault hielo, I gave you a B because I had already found solution prior to your posting.... :-/
0
piattndAuthor Commented:
Rob,

I'll give that a shot on the next HTA I use.  I was actually curious if there was a way to just "push" the button through code, which appears to be what you suggested.
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
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.