The answer: Current browsers do not adhere to this part of the html specification. The event only fires when it is activated by a user - and does not fire when activated by code.
The W3C Document Object Model (DOM) Level 2 HTML Specification says that submit() "submits the form. It performs the same action as a submit button."
However, this browser non-compliance is documented in the DOM Level 2 HTML Issues List. The Resolution: "Unfortunately, given the differences between implementations, it was not possible to find a common ground on this issue. No changes were in the specification. You cannot rely on having an event when invoking the submit() method."
The Microsoft reference is more explicit, "The submit method does not invoke the onsubmit event handler."
Many people have written on this topic, including codestore and alexking.
ASCII Lookup Table (by the way, ASCII stands for American Standard Code for Information Interchange)
Discussion of capturing the ASCII key code value pressed in Firefox and Internet Explorer 6
Here is a quick code example that demonstrates one workaround for this problem:
<form id="searchForm" name="searchForm" method="get" onsubmit="return validateMyForm()">
This function will return a boolean value. This return value determines whether the form is submitted or not.
<label>Search: </label><input name="textboxSearch" id="textboxSearch" maxlength="128" type="text" />
<select name="selectFilter" id="selectFilter" onkeypress="return handleKeystroke(event)">
<option selected value="First">First</option>
This function will attempt to submit the form if the Enter key is pressed.
<input class="submitButton" type="submit" value="Go" title="Go" />
//This function handles the onkeypress event.
//If the Enter key is pressed, it attempts to submit the form.
//Browser compatibility check
//Browser used: Internet Explorer 6
keyPressed = e.keyCode;
alert('handleKeystroke: IE property: keyCode');
//Browser used: Firefox
keyPressed = e.which;
alert('handleKeystroke: FF property: which');
alert('handleKeystroke: key=' + keyPressed);
//13 = ASCII code for Enter key
if (keyPressed == 13)
alert('handleKeystroke: pressed Enter');
//Directly calling document.searchForm.submit() will not fire the form's onsubmit event handler.
alert('handleKeystroke: pressed another key');
//This function performs validation and any other pre-form-submit tasks.
//The form will only be submitted if this function returns true.
var isValid = confirm('Do you want to submit the form?');
alert('validateMyForm: isValid = ' + isValid);
//This function simulates the onsubmit event handler.
//first, call the same validation function used in the form.onsubmit event handler
var thisresult = validateMyForm();
alert('submitMyForm: validateMyForm returned: ' + thisresult);
//if the function returned true, submit the form