i have button submit :
<input type="button" id="button_sign_in" class="button_sign_in" value="sign in"/>
and have jquery submit :
$(document).ready(function() { $('#button_sign_in').click(function(){ console.log('login'); $.ajax ({ url: "login", type: "post", data: $('#login_form').serialize(), datatype:'json', success: function (data) { if (data.status=='success') { window.location='home.php'; } else { $('#button_sign_in').shake(4,6,700,'#cc2222'); $('#username').focus(); } }, error: function (e) { console.log('error:'+e); } }); }); });
the problem : can't submit using enter key, user must click button sign in submit.
what want ? set enter key js function, user can choose submit using enter key or click button sign in.
thanks help.
check demo http://jsfiddle.net/yeyene/hd7zqafg/
first click on result frame (because there frames), , press enter, submit button click event fire on enter key press & on button click.
$(document).ready(function() { // enter keyd $(document).bind('keypress', function(e) { if(e.keycode==13){ $('#button_sign_in').trigger('click'); } }); $('#button_sign_in').click(function(){ alert('you click submit!'); console.log('login'); $.ajax ({ url: "login", type: "post", data: $('#login_form').serialize(), datatype:'json', success: function (data) { if (data.status=='success') { window.location='home.php'; } else { $('#button_sign_in').shake(4,6,700,'#cc2222'); $('#username').focus(); } }, error: function (e) { console.log('error:'+e); } }); }); });
Comments
Post a Comment