Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Friday, February 10, 2012

Bind or unbind html form to enter key pression

You should need to force the enter key pression, on a html form, to a javascript function(instead of the tag attribute action content).

$(document).ready(function(){
    $("#recoverUsernameFormId").bind("keypress", function(e) {
        if (e.keyCode == 13) {
            callYourFuncion();
            return false;
        }

    });
});


At the same way, you should need to unbind the enter key pression to the html form.


$(document).ready(function(){
    $("#recoverUsernameFormId").bind("keypress", function(e) {
        if (e.keyCode == 13) {
            return false;
        }

    });
}); 


Bye...