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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript submitting a form twice

Status
Not open for further replies.

ajefferies

Programmer
Nov 23, 2000
4
GB
I have a problem with a JavaScript function submitting a form twice. It looks like:

<a href=&quot;javascript:parent.frames['fn'].submitFunction();&quot;>
<img src=&quot;/image.gif&quot; border=&quot;0&quot;> submit
</a>

submitFunction() validates and submits a form.

What actually happens (in some versions of IE5.0) is the form is POSTed correctly, with the right attributes, and the right cookie. Immediately after, another call to the same url (servlet) is made as a GET, no attributes, no cookie.
The servlet performs a client-side redirect.

The same thing happens if I submit the form like:

javascript:parent.frames['fn'].document.forms['form'].submit();
and use onSubmit to validate.

Anyone know what's up? Currently, the second (invalid) attempt overwrites the first, and so an error is returned to the user. Or, does anyone know if I can discard the second submission without upsetting the browser? Netscape &amp; IE5.5 does not have this problem.

Many thanks,
Andy.
 
Don't use onSubmit. Use just the link or onClick. Do your validation and then do submit(); Also, be careful that the form does not autosubmit on enter.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top