Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > auto form submit on ENTER key

Reply
Thread Tools

auto form submit on ENTER key

 
 
ppcguy
Guest
Posts: n/a
 
      08-06-2005
i've got a login page with name and password and
would like the form to be submitted with the
user presses on either of the two input fields.

it works if i do this

<INPUT TYPE="Submit" NAME="Submit" VALUE="Login">

but does not for this:

<INPUT TYPE="Button" NAME="Submit" VALUE="Login"
onclick="onSaveClicked(this)">

help!!!



 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      08-06-2005
ppcguy wrote:

> it works if i do this
> <INPUT TYPE="Submit" NAME="Submit" VALUE="Login">
> but does not for this:
> <INPUT TYPE="Button" NAME="Submit" VALUE="Login"
> onclick="onSaveClicked(this)">


So don't do that! (Depending on JavaScript is a poor idea anyway)

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
 
 
 
Roy Schestowitz
Guest
Posts: n/a
 
      08-07-2005
ppcguy wrote:

> i've got a login page with name and password and
> would like the form to be submitted with the
> user presses on either of the two input fields.
>
> it works if i do this
>
> <INPUT TYPE="Submit" NAME="Submit" VALUE="Login">
>
> but does not for this:
>
> <INPUT TYPE="Button" NAME="Submit" VALUE="Login"
> onclick="onSaveClicked(this)">
>
> help!!!


Why would you ever want to use the latter if the former works? The simpler
form gives you the correct behaviour by default...

Roy

--
Roy S. Schestowitz
http://Schestowitz.com
 
Reply With Quote
 
Safalra
Guest
Posts: n/a
 
      08-08-2005
Roy Schestowitz wrote:
> ppcguy wrote:
> > i've got a login page with name and password and
> > would like the form to be submitted with the
> > user presses on either of the two input fields.
> > it works if i do this
> > <INPUT TYPE="Submit" NAME="Submit" VALUE="Login">
> > but does not for this:
> > <INPUT TYPE="Button" NAME="Submit" VALUE="Login"
> > onclick="onSaveClicked(this)">

>
> Why would you ever want to use the latter if the former works? The simpler
> form gives you the correct behaviour by default...


I presume the the original poster wants to do something with Javascript
before submitting the form. If this is input validation (the most
common use of Javascript in forms), it's a really bad idea: never rely
on client-side validation - always perform it on the server side for
security.

--
Safalra (Stephen Morley)
http://www.safalra.com/programming/javascript/

 
Reply With Quote
 
Benjamin Niemann
Guest
Posts: n/a
 
      08-08-2005
Safalra wrote:

> Roy Schestowitz wrote:
>> ppcguy wrote:
>> > i've got a login page with name and password and
>> > would like the form to be submitted with the
>> > user presses on either of the two input fields.
>> > it works if i do this
>> > <INPUT TYPE="Submit" NAME="Submit" VALUE="Login">
>> > but does not for this:
>> > <INPUT TYPE="Button" NAME="Submit" VALUE="Login"
>> > onclick="onSaveClicked(this)">

>>
>> Why would you ever want to use the latter if the former works? The
>> simpler form gives you the correct behaviour by default...

>
> I presume the the original poster wants to do something with Javascript
> before submitting the form. If this is input validation (the most
> common use of Javascript in forms), it's a really bad idea: never rely
> on client-side validation - always perform it on the server side for
> security.


Sure, but this does not imply that (unobstrusive) client-side validation
must not be done. If it degrades well on non-JS user-agent it can provide a
better usability for the website, saving the user from extra server
roundtrips. But you'll have to implement the validation twice (client-side
JavaScript, server-side whatever) and keep these implementations in sync.

What the OP should do, to do form validation:

<INPUT TYPE="Submit" NAME="Submit" VALUE="Login" onclick="return
validateForm()">

where validateForm() returns 'false', if validation failed.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STRUTS- <html:submit> does not submit on pressing Enter key Megha Vishwanath Java 2 10-02-2009 12:52 PM
Cross Browser "Form Auto Submit on Enter" mattgarvin@gmail.com Javascript 2 02-09-2007 03:09 PM
Enter Key H*ll, control enter key submit button BrianDH ASP .Net Web Controls 3 01-12-2005 08:29 PM
Form submit - hitting enter does not trigger Submit button ASP General 2 10-25-2004 03:37 PM
STRUTS-<html:submit> -Hitting enter key does not submit the form Megha Vishwanath Javascript 3 07-20-2004 05:45 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57