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 t开发者_如何学Che form to automatically submit when the user presses the Enter key.
How would I do this with HTML?
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();
}
});
});
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
(http://www.htmlcodetutorial.com/forms/index_famsupp_157.html)
this probably would help ;)
精彩评论