You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Reynolds <ji...@gmail.com> on 2005/11/04 14:41:31 UTC

Client Side Validator Fails When Submit from Javascript

I have been playing with the client-side validation, and ran into a
problem last night that I can docuemnt, but cannot figure out why it
fails.

The below file, shows a form and when you hit the submit, presents the
appropriate alert box with the proper message. All is good, and works
when the "submit" is pressed.

But if you try and use a javascript:document.form.submit(), the
document is submitted but the alert does NOT work. So basically the
validation fails.

I have tried multiple ideas, and all have not worked. But I really
need the ability to do submits from a javascript: Technically, I was
unare of any difference between a submit button, and a submit form
using the javascript:

Anyone?

Here is the jsp page, in case one sees something odd:

<%@ include file="/tags.jsp" %>

<html:html locale="true">
<head>
    <title>fyi</title>
<html:base/>
</head>
<body bgcolor="white">
<html:form action="/AddressJavascriptValidation" method="post"
onsubmit="return validateAddressForm(this);">

<td align="center" colspan="2">
<font size="4"><b>Please Enter the Following Details</b></font>
</tr>
<tr>
<td align="right">
<b>Name</b>
</td>
<td align="left">
<html:text property="name" size="30" maxlength="30"/>
</td>
</tr>
<tr>
<td align="right">
<b>Address</b>
</td>
<td align="left">
<html:text property="address" size="30" maxlength="30"/>
</td>
</tr>


// HERE IS A LINK USING SIMPLE JAVASCRIPT TO SUBMIT THAT
// FAILS.********************************************************************

<a href="javascript:document.AddressForm.submit()">doit</a>

<tr>
<td align="right">
<b>E-mail address</b>
</td>
<td align="left">
<html:text property="emailAddress" size="30" maxlength="30"/>
</td>
</tr>

<tr>
<td align="right">
<html:submit>Save</html:submit>
</td>
<td align="left">
<html:cancel>Cancel</html:cancel>
</td>
</tr>
</table>
</div>

<!-- Begin Validator Javascript Function-->
<html:javascript formName="AddressForm"/>
<!-- End of Validator Javascript Function-->

</html:form>
</body>
</html:html>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org