Default button

I have two text boxes and a button. i want the button to be able
to be utilized by pressing the enter key. how do i do this?

<input type=button value="Login" onClick="Login()">
Mike MillerSoftware EngineerAsked:
Who is Participating?
 
monvelasquezCommented:
would it be ok if you do it like this...

Here is a working example for IE:

<HTML>
<HEAD>
<SCRIPT language="javascript">
 function Login()
 {
    alert('Submitted');
    return false;
 }
</SCRIPT>
</HEAD>

<BODY>
<FORM name="myform" action="javascript:Login();" >

  <input type="TEXT" name="userName" />
  <input type="PASSWORD" name="password" />
  <input type="SUBMIT" value="Login" />

</FORM>
</BODY>
</HTML>
0
 
knightEknightCommented:
Here is a working example for IE:

<HTML>
<HEAD>
<SCRIPT language="javascript">
 function Login()
 {
    alert(0);
    return false;
 }
</SCRIPT>
</HEAD>

<BODY>
<FORM name="myform" action="javascript:alert('Submitted');" >

  <input type="text" name="userName" />
  <input type="text" name="password" onkeyup="if(event.keyCode==13)this.form.submit();" />
  <input type="button" value="Login" onClick="Login()" />

</FORM>
</BODY>
</HTML>
0
 
jaysolomonCommented:
if the user tabs to the button, and presses enter it will "click it" and do your Login function

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
knightEknightCommented:
oops, but my Login function is just a stub -- obviously, you should replace it with your own.  The key is in the onkeyup event handler.  I am working on a NS version too...
0
 
knightEknightCommented:
This one should work in NS too:

 <input type="text" name="password" onkeyup="var event = e?e:event; if(event.keyCode==13)this.form.submit();" />
0
 
knightEknightCommented:
oops, scratch that last post ... go with the first one instead.
0
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.

All Courses

From novice to tech pro — start learning today.