auto form submit on ENTER key

Discussion in 'HTML' started by ppcguy, Aug 6, 2005.

  1. ppcguy

    ppcguy Guest

    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!!!
     
    ppcguy, Aug 6, 2005
    #1
    1. Advertising

  2. 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
     
    David Dorward, Aug 6, 2005
    #2
    1. Advertising

  3. 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
     
    Roy Schestowitz, Aug 7, 2005
    #3
  4. ppcguy

    Safalra Guest

    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/
     
    Safalra, Aug 8, 2005
    #4
  5. 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/
     
    Benjamin Niemann, Aug 8, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Megha Vishwanath
    Replies:
    2
    Views:
    9,842
    tutorialsmaster
    Oct 2, 2009
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    400
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    475
  4. Megha Vishwanath
    Replies:
    3
    Views:
    717
    Megha Vishwanath
    Jul 20, 2004
  5. Replies:
    2
    Views:
    168
Loading...

Share This Page