Solved

Enter key to respond in a text box

Posted on 1998-10-28
6
154 Views
Last Modified: 2008-03-10
I want a text box which is password type should be able to respond an enter key i.e; on pressing the enter key another page needs to be called. I am also not able to trap the ASCII values  of keys pressed from the keyboard in Javascript.
0
Comment
Question by:PSV
  • 3
  • 3
6 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
ID: 1273092
<html>
<head>
<script>
NS = (document.layers);
IE = (document.all);
function f1(e) { // This takes over the enter key in the specified field
   if((NS && e.which == 13) || (IE && window.event.keyCode == 13)) {
      document.myForm.submit();
      return false; // cancel the enter (Dings in Netscape)
   }
}
</script>
</head>
<BODY>
Here is a simple code for submitting a form with multiple fields.
The form is submitted by hitting enter in field 1 by assigning a fuction to the
document.form.field.onKeypress.
<FORM name=myForm action="enter.html">
1.<INPUT TYPE="PASSWORD" NAME="FirstField"  size=40><BR>
<BR>2.<INPUT TYPE="text" NAME="SecondField"  size=40>
</FORM>
<SCRIPT LANGUAGE="JavaScript1.1">
   document.myForm.FirstField.onKeyPress = f1;
</script>

<P>use document.onkeypress = keyHandler; for MSIE
and window.captureEvents(Event.KEYPRESS) with window.onkeypress  for netscape
to get all keypresses (and for example cancel enter unless the last field has the focus)
</body>
</html>


0
 
LVL 4

Expert Comment

by:rafistern
ID: 1273093
If you make a form with only one button then an <Enter> will submit the form:

<form action="whatever">
<input type="password" name="password" size=10>
<input type="submit" value="OK">
</form>
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1273094
My solution will work in any browser, although it wasn't really what you asked.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1273095
PS: A form with a single text/password field will submit with the enter in most browsers without the JavaScript:
<FORM...>
<INPUT TYPE="PASSWORD">
</FORM>

but IE3 (last time I looked) will not submit the form if there is one more entry field on the page (even if it is not in the same form)

All the 'normal' keys are passed in e.which or window.event.keyCode and can be trapped. The 13 is the enter key
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1273096
Rafi: Stop submitting at the same time as me ;-)

Michel
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1273097
Michel's last comment seems to me to be an optimal solution if it works. However I would prefer to have the button there for people who like clicking buttons - it makes the user interface more intuitive.

(I submit to the same threads as you because there seem not be many active experts on European timezones. Whatever is happening in the morning on our side of the world is the middle of the night in the States.)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now