Solved

Default button

Posted on 2003-11-17
6
333 Views
Last Modified: 2010-04-09
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()">
0
Comment
Question by:mwmiller78
  • 4
6 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 9765265
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9765273
if the user tabs to the button, and presses enter it will "click it" and do your Login function

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9765275
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 33

Expert Comment

by:knightEknight
ID: 9765287
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 9765359
oops, scratch that last post ... go with the first one instead.
0
 
LVL 3

Accepted Solution

by:
monvelasquez earned 50 total points
ID: 9768159
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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Put glyphicon in my input button 4 46
Bad <form> statement? 9 31
send keys not working in vba 7 58
document.getElementById not worj with 2 IDs with the same name 10 39
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…

776 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