Hello, Welcome to my blog. If you like feel free to refer others

Wednesday, 27 June 2012

Making a button default clickable when enter key is pressed

Many times we want that on pressing enter key the submit button should be automatic click. For example on login page after typing password generally users press enter key and want that submit button will call but nothing happen.
 Here is the JavaScript code for it:

function doClick(buttonName, e) {
            var key;
            if (window.event)
                        key = window.event.keyCode;     //IE
                        key = e.which;     //firefox
            if (key == 13) {   //Get the button the user wants to have clicked
                        var btn = document.getElementById(buttonName);
                        if (btn != null) { //If we find the button click it
                                    event.keyCode = 0

No comments:

Post a Comment