[thelist] dHTML Form Elements && tip re: Disabling the <enter> key to submit a form.

jeff jeff at members.evolt.org
Fri Dec 1 10:54:45 CST 2000


Tab,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: To keep your user from inadvertantly submitting your
: form by pressing <enter>, try getting rid of the <input
: type="submit"> also take the Action="" and Method=""
: out of your <form> tag (but DO give it a Name="").
:
: [remaining tip snipped]
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

while you're tip addresses another list member's specific needs, i have a
great concern with the solution and it's far-reaching effects.

<tip type="Usability & JavaScript" author=".jeff">

unless you're building administrative tools or an intranet where you have a
very defined audience and a clearly defined system requirements
specification (i.e., javascript, ie5+, etc.) then you should *never* mess
with anything in the <form> tag.  reducing the ability of a form to submit
except through the explicit call of the submit() method renders your form
sterile for non-js users as does scripting the method and action attributes
and removing the physical attributes from the <form> tag.

second, scripting these things makes it much more difficult to debug your
applications.  while it may be appealing to be able to post to two different
scripts the reality is that both scripts that take the form submission are
likely very similar.  rather than posting to two separate ones based on the
button that's clicked, simply combine the two scripts and run a conditional
based on which submit button was clicked.  this can be easily determined by
naming both buttons the same and just checking their value on the processing
page.

finally, relying on the submit() method makes it more difficult to validate
your form data prior to submission.  instead of being able to rely on the
onSubmit event handler for the form (which will not fire if the form is
submitted via the submit() method) you'll have to manually call the
validation routine, validate all the fields, maintain some sort of check
that data is indeed valid and use that value to determine if you should then
call the submit() method.  this is much less elegant than simply calling the
validation function from the onSubmit event handler and simply having it
return true or false.

conclusion:  use of the submit() method is a kludge and not recommended.  do
it the right way with the onSubmit event handler.  castrating forms for
non-js users is very bad karma - just don't do it.  always build a form to
work without javascript at all.  then, go in and add alittle to take care of
non-mission critical things that make it easier to use for those with
javascript without reducing the ability of the form to work for those
without.

</tip>

thanks,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list