
Originally Posted by
johnnyi
I have a series of buttons on a form - but when the user hits the 'Enter' key on their keyboard, the first button in sequence (which luckily is a Save Form button) is automatically executed.
Yes, it's a useful feature.
Q: Is there a way to disable buttons from being executed from the keyboard 'Enter' stroke, and only from a mouseclick?
You can try, but you'd be better off educating users not to use the Enter key to submit when multiple buttons are present. Alternatively, don't use multiple buttons; use another control to indicate what action should take place (admittely, not always possible).

Originally Posted by
jscheuer1
HTML Code:
<button>Text to Display</button>
[...] an IE specific kind of button that has gained general support in other browsers [...]
Good grief no! The button element is a standard HTML 4 feature, which IE utterly fails to implement properly, rendering a very useful control unusable on the Web (*grumbles*). 
Try onkeydown="return false;"
That could prevent any kind of keyboard navigation from activating controls, which is clearly not a good thing.
A rather dirty, lightly-tested version is:
Code:
var Keys = { VK_ENTER : 13 };
function getKeyCode(event) {
return ('number' == typeof event.keyCode)
? event.keyCode
: ('number' == typeof event.which)
? event.which
: NaN;
}
Code:
function validate(form) {
if(validate.enterPressed) {
validate.enterPressed = false;
return false;
}
/* Other validation checks */
return true;
}
HTML Code:
<form ... onkeydown="validate.enterPressed=(getKeyCode(event)==Keys.VK_ENTER);"
onsubmit="return validate(this);">
However, I still don't advise doing this.
Mike
Bookmarks