d_i_r_t_y has asked for the wisdom of the Perl Monks concerning the following question:

this is a little bizarre to me...

is it just my stupidity, or is it that the regular old html form element <input type="text"> almost always submits the form when the <return> key is pressed?

i was always under the impression that (at least in netscape), the focus would merely shift to the next form element on the page, rather than actually submitting the form. The pages in question are 'straight' html, using a plain old stylesheet and some javascript rollovers, but no other wacky .js code. This behaviour occurs on both linux netscape 4.75 and KDE2.1 konqueror (which is a tres excellent browser IMHO...).

Could someone please explain this behaviour, and/or describe how i might turn it off?

thanks, d_i_r_t_y

Replies are listed 'Best First'.
Re: can anyone explain this codeinput type=
by dws (Chancellor) on Apr 18, 2001 at 04:08 UTC
    From Dynamic HTML: The Definitive Reference, page 264:
    Default behavior of the Enter key in forms has evolved into a recognized standard. When a form consists of a single text INPUT element, a press of the Enter (or Return) key automatically submits the form (as if the user had clicked on a SUBMIT button element). If the form consists of two or more text INPUT elements, the Enter (or Return) key does not automatically submit the form.

    What is left unstatated is when the behavior evolved into a recognized standard. YMMV with older browsers.

Re: can anyone explain this codeinput type=
by Eureka_sg (Monk) on Apr 18, 2001 at 05:43 UTC

    For a start, this question is non Perl-related. : )

    It is possible to use Javascript to disable the Enter key completely by using event capturing. Check out webreference for their columns on Javascript. I'm not sure which version of javascript is supported on KDE2.1, but you will need version 1.2 or above to support event handling

      Errr, small point, but the onSubmit handler is part of client side JS version 1.0

      So yes, you can disable submission using an onSubmit handler in your FORM tag, but you can't rely on it always working (but for 90% of users it will do the trick).

      cLive ;-)

        I'm not talking about disabling submission using onSubmit. I'm refering to capturing the "ENTER" key press event on the browser window and preventing the event to be routed to the form object.

Re: can anyone explain this codeinput type=
by Masem (Monsignor) on Apr 18, 2001 at 03:55 UTC
    It's pretty much limited to the browser with no way to disable it on most systems, especially from the server side of things.
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain