Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oN ENTER 2

Status
Not open for further replies.

100dtl

Programmer
Aug 18, 2003
313
GB
Can anyone tell me how I submit a form on pressing enter
 
Tried that, what i did was add another variable to the action line keeping post, that worked
 
I think that your main problem is this code
Code:
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;<%response.write dictLanguage.Item(Session(&quot;language&quot;)&&quot;_customerauthenticateform_2&quot;)%>&quot; ID=&quot;Submit1&quot; onClick=&quot;if(checkForm()){document.register.submit()}&quot; >

You should do something like this and the form will work without any onkeypress script code.

<form method=&quot;post&quot; action=&quot;referer.asp?ty=lg&quot; ID=&quot;FormReg&quot; name=&quot;register&quot;
onsubmin=&quot;return checkForm(this)&quot;
Code:
>
              <table width=&quot;100%&quot; border=&quot;0&quot; align=&quot;left&quot; cellpadding=&quot;0&quot; class=&quot;main&quot; ID=&quot;Table1&quot; >
                <tr> 
                  <td width=&quot;41%&quot; rowspan=&quot;2&quot; valign=&quot;top&quot;></td>
                  <td width=&quot;22%&quot; align=center><font color=&quot;#666666&quot; face=&quot;Arial, Helvetica, sans-serif&quot;><strong><br>

            <%response.write dictLanguage.Item(Session(&quot;language&quot;)&&quot;_customerauthenticateform_7&quot;)%></strong></font></td>
                  <td width=&quot;37%&quot; align =right><br>
 <%validate &quot;username&quot;, &quot;username&quot;%><%textbox &quot;username&quot;,&quot;&quot;, 20, &quot;textbox&quot;%>                   </td>
                </td>
                </tr>
                <tr> 
                  <td align=center><font color=&quot;#666666&quot; face=&quot;Arial, Helvetica, sans-serif&quot;><strong><%response.write dictLanguage.Item(Session(&quot;language&quot;)&&quot;_customerauthenticateform_5&quot;)%></strong></font></td>
                  <td align =right valign=&quot;bottom&quot;> <%validate &quot;password&quot;, &quot;required&quot;%><%textbox &quot;password&quot;,&quot;&quot;, 20, &quot;password&quot;%>
                                    </td>
                </tr>
                <tr>
                  <td height=&quot;33&quot; valign=&quot;top&quot;> </td>
                  <td align=center> </td>
                  <td align =right valign=&quot;bottom&quot;>
          <input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;<%response.write dictLanguage.Item(Session(&quot;language&quot;)&&quot;_customerauthenticateform_2&quot;)%>&quot; ID=&quot;Submit1&quot;>
                </tr>
                <tr> 
                  <td colspan=&quot;3&quot;><br></td>
                </tr>
              </table>    
</form>
Using 
function checkForm(frm)
{

if(frm.username.value==&quot;&quot;)
{
 alert(&quot;Username empty!&quot;)
 frm.username.focus()
 //cancel the submit.
 return false
}

//if all ok submit form with returning true
return true;
}

This should work with presing Enter also.

________
George, M
 
Eh, the event name is wrong
Instead of onsubmin should be onsubmit
Anyway, if you want to use event handlers for the form or submit button you should always use &quot;return functionName()&quot;
When function returns true it sends the event to the parent elements(Event Bubling, something like event.cancelBuble=false, by default) if it's false cancels event bubling to other elements there for, form wont submit
(event.cancelBuble=true)

Best way is to use the onsubmit event of the form, also you can send the form reference using this as function parameter which helps in finding the form controls.

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top