Search This Blog

Friday, 11 November 2011

Preventing Enter Button event from Form Submission

    if (document.layers)
        document.captureEvents(Event.KEYDOWN);
    document.onkeydown = function (evt) {
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if (keyCode == 13) {
        return false;
        //Your function here.
    }
    else
        return true;
    };

 OR

function preventEnter(evt) {
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if (keyCode == 13)
        return false;
    else
        return true;
};

Usage:  onkeydown="return preventEnter(event);"

No comments:

Post a Comment