Reputation:
I want my form to automatically switch from the username field to the password field as the user types in their information. I would also like the form to automatically submit when the user presses the Enter key.
How would I do this with HTML?
Upvotes: 2
Views: 2043
Reputation: 3721
(http://www.htmlcodetutorial.com/forms/index_famsupp_157.html)
this probably would help ;)
Upvotes: 1
Reputation: 382806
You need javascript for that:
var el = document.getElementById('field_id');
el.onkeypress = function(event){
var key = event.keycode || event.which;
if (key === 13) {
document.FormName.submit();
}
};
jQuery: (based on comment)
$(function(){
$('#form_id:input').keypress(function(event){
var key = event.keycode || event.which;
if (key === 13) {
$(this).parents('form').submit();
}
});
});
Upvotes: 5
Reputation: 46
Example-
<FORM action="..." method="post">
<P>
<LABEL for="fuser" accesskey="U">
User Name
</LABEL>
<INPUT type="text" name="user" id="fuser">
</P>
</FORM>
See details HERE
Upvotes: 2