CODE to prevent submission via return key not always working
Posted: Tue Dec 15, 2009 10:25 am
I do not know javascript at all, but I've been using the follwing code to prevent users from accidently submiting forms by hitting the return key. I have discovered that this works for text fields, but not checkboxes and radioboxes. If they hit enter from a radiobox, the form submits. If someone has a code snippet they can share that REALLY prevents use of the return key, I'd appreciate it.
Code: Select all
<script type="text/javascript">
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
</script>