Share this page 

Trigger a submit with Enter Tag(s): Varia


The trick is to use 2 forms. The first one contains all the fields except the last one. The second form contains the last field and in the submit function, we read the values from the first form and put them in hidden fields defined in the second form. After validation, the submit function returns true or false to submit or not.
<HTML><HEAD> 
 <SCRIPT LANGUAGE="JavaScript">
 function submit1() {
   document.PwdForm.pwd.focus();
   /*  don't submit yet */
   return false;
   }

 function submit2() {
   document.PwdForm.username.value =
       document.LoginForm.username.value;
   /* perform any validation here */
   /* and submit */
   return true;
   }
 </SCRIPT>
</HEAD><BODY>
 <FORM NAME="LoginForm" onSubmit="return submit1()">
 <P>User Name: <INPUT NAME="username" TYPE="TEXT">
 </FORM>

 <FORM NAME="PwdForm" onSubmit="return submit2()">
 <INPUT NAME="username" TYPE="HIDDEN">
 <P>Password: <INPUT NAME="pwd" TYPE="PASSWORD">
 </FORM>
 </BODY></HTML>