Hi,
I have a form with a text field. I want the form to be submitted when the value is updated. Originally I had the form submit onChange, but if the enter key is pressed instead of tab, the form does not get sumitted. It is the only text field on the form, so it's very likely someone would enter the new quantity and press enter.
I added the onKeyDown event with this code (found here
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21362644.html), but it doesn't work....
function HitEnter()
{
if(event.KeyCode == 13)
{
document.form1.action ="change_qty.cfm";
document.form1.submit();
nextCtrl.focus(); // simulate tab key
event.bubleCancel = true;
event.returnValue = false; // no more processing..
}
}
Thanks a lot for any help,
Bonnie
<html>
<body>
<form onsubmit="yourStuffGoesHer
<input type="text" name="key" value="value">
</form>
</body>
</html>
Forms have an onsubmit event, and you can trap it to do what you want instead. Since hitting enter tries to submit the form, that's the same as having an event handler that traps a press of the Enter key. Theoretically, the "return false" shouldn't be necessary since you're submitting the form somewhere, but that line will actually stop the form submission from the Enter key. However, in case the stuff you're doing doesn't cause a redirect or the script keeps going, the "return false" will keep the form form submitting to itself.
Hope that helps.