Solved

How to make an Input field recognize the enter keystroke

Posted on 2008-10-31
7
728 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:piattnd
  • 4
  • 2
7 Comments
 
LVL 12

Author Comment

by:piattnd
ID: 22853688
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
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22854553
>> 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
 
LVL 12

Author Closing Comment

by:piattnd
ID: 31512173
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 65

Expert Comment

by:RobSampson
ID: 22854716
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
 
LVL 82

Expert Comment

by:hielo
ID: 22855576
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
 
LVL 12

Author Comment

by:piattnd
ID: 22872520
My fault hielo, I gave you a B because I had already found solution prior to your posting.... :-/
0
 
LVL 12

Author Comment

by:piattnd
ID: 22872566
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now