Solved

How to make an Input field recognize the enter keystroke

Posted on 2008-10-31
7
737 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ebay style="image-orientation: 90deg;" 2 40
Using VBscript & RegEx, how can I match lines starting with Oracle word 17 59
Html test in IIS 4 20
Clear Filter 8 41
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 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