[thelist] Form Submittal on Enter

Andrew Clover and at doxdesk.com
Mon Jan 28 12:17:00 CST 2002


Josh <evolt at efeingold.com> wrote:

> I have noticed that IE4.0 (and perhaps others) will submit a form when the
> user hits the "Enter" key even when there is more than one field in the
> form.

Yes. You'll be pleased to know all other new browsers emulate IE's
behaviour, contradicting the HTML spec.

> Do any of you have Javascript solutions to prevent the submission of the
> form unless the Submit button was pressed?

Write an onsubmit handler that refuses to submit the form unless a flag is
set. Have the legitimate submit button set that flag. eg.

  <script type="text/javascript"><!--
    var submitclicked= false;
  </script>

  <form method="POST" action="..." onsubmit="return submitclicked;">

  <input type="submit" onclick="submitclicked= true;">

--
Andrew Clover
mailto:and at doxdesk.com
http://and.doxdesk.com/



More information about the thelist mailing list