HTML - Press enter in text field set focus on other text field -
i want create form in html 3 textfield , 1 button. in load page or refreshed txt1 textfield automatically focused, when pressing enter key txt2 focused , if pressed enter again txt3 focused , when pressed enter again submit.
is there knows how it? please help... code example below...
thanks...
<form name="form1" action="filename.php" method="post"> text1: <input type="text" name="txt1" autofocus><br> text2: <input type="text" name="txt2"><br> text3: <input type="text" name="txt3><br> <input type="submit"> </form>
you can combination of html , jquery:
html:
<form name="form1" action="filename.php" method="post"> text1: <input type="text" id="txt1" name="txt1" autofocus><br> text2: <input type="text" id="txt2" name="txt2"><br> text3: <input type="text" id="txt3" name="txt3"><br> <input type="submit" /> </form>
jquery:
$(document).ready(function(){ $('input').on('keypress', function(e) { if(e.which == 13) { switch($(this).attr('id')){ case 'txt1': $('#txt2').focus(); e.preventdefault(); break; case 'txt2': $('#txt3').focus(); e.preventdefault(); break; } } }); });
Comments
Post a Comment