You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Chawla, Yogesh" <yo...@hpsglobal.com> on 2003/11/20 08:56:59 UTC
URGENT :: Disable enter key in HTML:FORM by using onKeyPress func
tion
Hi,
In normal forms, we can disable enter key by calling onKeyPress() function
in the form tag.
However, this is not supported in the <html:form> definition for Struts.
Can anybody give a solution to this ...
Thanks,
Yogesh Chawla
DISCLAIMER: The information in this message is confidential and may be
legally privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorised. If you are not the intended
recipient, any disclosure, copying, or distribution of the message, or any
action or omission taken by you in reliance on it, is prohibited and may be
unlawful. Please immediately contact the sender if you have received this
message in error. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: URGENT :: Disable enter key in HTML:FORM by using onKeyPress function
Posted by Sergey Smirnov <si...@exadel.com>.
"Chawla, Yogesh" <yo...@hpsglobal.com> wrote in message
news:8E8F90E0E0E3D71184BB00902785FCE13F5EE1@HPSB31EX57...
> Hi,
>
> In normal forms, we can disable enter key by calling onKeyPress() function
> in the form tag.
> However, this is not supported in the <html:form> definition for Struts.
>
> Can anybody give a solution to this ...
>
If it is really urgent, you can write the following line just after
</html:form>
<script type="javascript">document.forms[0].onkeypress=function(){return
foo();}</script>
where foo() is your custom javascript function that return true or false. If
it is false, the action will be stopped.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: URGENT :: Disable enter key in HTML:FORM by using onKeyPress
func tion
Posted by James Mitchell <jm...@apache.org>.
On Thu, 20 Nov 2003, Chawla, Yogesh wrote:
> Hi,
>
> In normal forms, we can disable enter key by calling onKeyPress() function
> in the form tag.
> However, this is not supported in the <html:form> definition for Struts.
>
> Can anybody give a solution to this ...
Your best bet for stopping the user from submitting a form with JavaScript
is to handle it in the form tags onsubmit attribute.
Here's an example from a recent app I'm working on:
I needed a way to make sure that users entered a minimum of 3 (or some
configurable value) characters when performing a search. The problem is
that it can be 3 characters from any combination of 3 fields.
<html:form action="/manageUsers"
onsubmit="return doMyValidation(this)"
focus="view.registration.security.userName">
...and at the bottom of the page I do this...
<script language="JavaScript"/>
function doMyValidation(form){
u =
form.elements['view.registration.security.userName'].value.length;
f =
form.elements['view.registration.personal.firstName'].value.length;
l =
form.elements['view.registration.personal.lastName'].value.length;
if (u + f + l < <bean:message
key="validation.min.search.chars"/>){
alert('<c:out value="${msg}"/>');
return false;
}
return validateSearchForm(form);
}
</script>
<html:javascript formName="searchForm"
dynamicJavascript="true"
staticJavascript="true"/>
...what that does is allow me to insert my own custom validation and, if
that passes, then the validator-generated one is run.
>
> Thanks,
>
> Yogesh Chawla
> DISCLAIMER: The information in this message is confidential and may be
> legally privileged. It is intended solely for the addressee. Access to this
> message by anyone else is unauthorised. If you are not the intended
> recipient, any disclosure, copying, or distribution of the message, or any
> action or omission taken by you in reliance on it, is prohibited and may be
> unlawful. Please immediately contact the sender if you have received this
> message in error. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
--
James Mitchell
Software Developer / Struts Evangelist
http://www.struts-atlanta.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org