This is probably related to non-standard behavior in the IE browser that
when you hit the enter key with a form present and with a focus on any form
input element, the action is equivalent to a form submission. (I believe
with other browsers that follow the standard, user is required to interact
with a submit control, such as a pressing a button of type="submit").
In that case, you need an
onSubmit="myFormSubmitHandler()"
as an attribute in the appropriate place, within a 'form' start tag,
according the specs I read.
Since the onKeyPress event might be handled before the onSubmit event, you
could set a global variable from within its handler that could be referenced
later as the thread of execution passes to the onSubmit handler
[myFormSubmitHandler()] so as to know whether to proceed with the form
submission (return true) or not (return false). Alternatively, you might
pass the event object as an arg to myFormSubmitHandler(), see what
information you could extract from it, if that is enough for deciding
whether to proceed.
Quote:
> Thanks!
> I tried as you said and it seemsto work except...
> <input type="text" name="mytextbox" onkeydown="if (event.keyCode == 13)
> {return false;}">
> If I hit enter in this field it still submit's the form.
> Any idea why?
> Thanks
> Anthony Sullivan MCP, GMT, GST
> Analyst/Programmer
> Ajilon Services, Inc
> Check out the ASP FAQ! http://www.aspfaq.com
> "From the mouths of babes comes ... slobber."
> >On keypress event say :
> >if (event.keycode == 13)
> > event.returnvalue = false ;
> >> How can I trap a particular key?
> >> thanks!
> >> --
> >> Anthony Sullivan MCP, GMT, GST
> >> Analyst/Programmer
> >> Ajilon Services, Inc
> >> Check out the ASP FAQ! http://www.aspfaq.com
> >> "From the mouths of babes comes ... slobber."