Question

This is my login.jsp page,here i have 2 text fields when i enter user name in first text field and hits Enter key from keyboard it is not going to next text field.how can i do this? thanks for your help.

<body>         
<div id="wrapper"> 
    <table width="90%" border="0" align="center"  cellpadding="0"  cellspacing="0" > 
        <tr> 
            <td width="15%"><input name="username" type="text" id="username" value="username"/></td> 
            <td><input name="password" type="password" id="password" value="password"/></td> 
        </tr> 
        <tr><td>
                &nbsp;
            </td></tr>
        <tr> 
            <td align="right"  valign="bottom" ><input type="button"  name= "button"  id= "button"   value= "Submit"   /></td> 
        </tr> 
    </table> 
</div>      

Was it helpful?

Solution

To change focus to another inputtext people usually hit tab instead of enter..

However you can do that with jquery event handler..

$( "#your-username-input" ).keypress(function( event ) {
//press enter button
if ( event.which == 13 ) {
 $( "#your-other-input" ).focus();
}

OTHER TIPS

Two options for web browsers:

  1. You can press TAB instead

  2. you can reprogram your keyboard with the tab key where the enter key is ;) ;)

$("#username").on('keydown', function(event) {

if(event.which == 13) {// Enter key pressed

     event.preventDefault();

     /* $this = $(this);

     $this.focus();

     var value = $this.val();

     $this.val(''); // clear the field 

     // do stuff with the value*/

     }

});

Same will be for the password

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top