Solved

How to make an Input field recognize the enter keystroke

Posted on 2008-10-31
7
718 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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

744 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

16 Experts available now in Live!

Get 1:1 Help Now