|  | Posted by Benjamin Niemann on 07/07/20 11:23 
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/
  Navigation: [Reply to this message] |