Pressing Enter Key Throwing on the Home Page
-
Hello Friends, I've designed a contact page for the clients. But as i press Enter key from the keyboard it throws me on the Home Page or Default Page. But it must either save the record or fire the validation if the textboxes are empty. Thnx
-
Hello Friends, I've designed a contact page for the clients. But as i press Enter key from the keyboard it throws me on the Home Page or Default Page. But it must either save the record or fire the validation if the textboxes are empty. Thnx
You ought to trap the button click event and if the event keyCode turns out to be of ENTER key, then invoke the submit button click event.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
You ought to trap the button click event and if the event keyCode turns out to be of ENTER key, then invoke the submit button click event.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis LevinsonThe following JS should perform the above operation:
function checkEnter(e) { var characterCode; if ( e && e.which ) { e = e; characterCode = e.which; } else { e = event; characterCode = e.keyCode; } if ( characterCode == 13 ) { // 13 is the ASCII character code for the enter key document.getElementById('button_id').click(); } }
Attach the above function to the body / window elements onkeydown event.Clean code is the key to happiness.