Block Enter Key Submit
Sometimes you want a form to submit when the enter key is pressed, most times you don’t… here’s the code to block it from happening…
function blockEnter(evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode :
((evt.which) ? evt.which : evt.keyCode);
if (charCode == 13) {
return false;
} else {
return true;
}
}
<input onkeydown="return blockEnter(event);" name="search" size="40" type="text" />
About this entry
You’re currently reading “Block Enter Key Submit,” an entry on Elegando
- Published:
- 11.25.07 / 9pm
- Category:
- JavaScript
3 Comments
Jump to comment form | comments rss [?] | trackback uri [?]