...

View Full Version : enter key doesn't submit the form



mikeInCali
09-15-2005, 02:49 AM
This is the code i have in my jsp, but I have to click on the image link to submit the form. The client wants to be able to hit the enter key and login. I'm using struts. Can anyone help, please?

<html:form action="/logon" focus="username" onsubmit="return validateLogonForm(this);">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="5"><spacer type="block" width="1" height="1"></spacer></td>
</tr>
<tr>
<td class="InformationText"><bean:message key="prompt.username"/></td>
</tr>
<tr>
<td><html:text property="username" size="15" maxlength="15"/></td>
</tr>
<tr>
<td height="5"><spacer type="block" width="1" height="1"></spacer></td>
</tr>
<tr>
<td class="InformationText"><bean:message key="prompt.password"/></td>
</tr>
<tr>
<td><html:password property="password" size="15" maxlength="25" redisplay="false"/></td>
</tr>
<tr>
<td height="10" nowrap><spacer type="block" width="1" height="1"></spacer></td>
</tr>
<tr>
<td><html:link href="javascript:logonFormBean.submit();"><html:img src="images/g_login_btn.gif" alt="Login" width="46" height="7" border="0" /></html:link></td>
</tr>
</table>
</html:form>

martin_narg
09-15-2005, 01:34 PM
Use a submit button or an input image to submit the form, not a standard link.

Hope this helps

m_n

jbezweb
09-15-2005, 02:24 PM
ou could use a <html:button> or Image Button and onclick="document.formname.submit()"

Hope this helps

rm-f
09-15-2005, 02:39 PM
The answer depends of prog spec. Where the Enter key should triger logon, on entire page, some page part(s) or only in userName/password input fields?
I assume it is the latest:


function kpHandler(e) {
var code;
if(window.event) {
code = e.keyCode;
} else {
code = e.which;
}
if(code == 13) { // Enter
logonFormBean.submit();
}
}


<td><html:text property="username" onkeypress="kpHandler(event);" size="15" maxlength="15"/></td>
...
<td><html:password property="password" onkeypress="kpHandler(event);" size="15" maxlength="25" redisplay="false"/></td>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum