permaculture playing cards*
The moose likes Struts and the fly likes Multiple form submission on single click on button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Multiple form submission on single click on button" Watch "Multiple form submission on single click on button" New topic
Author

Multiple form submission on single click on button

Meenakshi Krishna
Greenhorn

Joined: Jul 06, 2007
Posts: 3
In my application i am using struts framework. In one page there is save button. On click of save button, it saves the data change on the page and renders the same sceen with the changed data. I am using <html:image> tag for this save button.And calling javascript onclick of this button. Problem which i am facing is of multiple requests is getting submitted while clicking on save. Please suggest why it is happening.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The problem is that you're using an <html:image> which is a type of submit button and a JavaScript submit with the onclick event. Both of these perform a submit, which is why you're getting two submits. The solution is to use one or the other, but not both. Either use the onclick event with an <img> tag, or use the <html:image> tag with no onclick event.


Merrill
Consultant, Sima Solutions
Meenakshi Krishna
Greenhorn

Joined: Jul 06, 2007
Posts: 3
Originally posted by Merrill Higginson:
The problem is that you're using an <html:image> which is a type of submit button and a JavaScript submit with the onclick event. Both of these perform a submit, which is why you're getting two submits. The solution is to use one or the other, but not both. Either use the onclick event with an <img> tag, or use the <html:image> tag with no onclick event.
Meenakshi Krishna
Greenhorn

Joined: Jul 06, 2007
Posts: 3
I have already tried using the <img> tag but it was not working. I run the tool httpwatch to test whether browser is sending the two request or what. And yes browser itself is sending the two request. Please suugest why it is happening and how to overcome this.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'll try to clarify:

When you put javaScript code such as "document.myForm.submit()" in an onclick event for a submit button (and <html:image> is a submit button), the result will be that the form submits twice: once from the submit button itself, and once from the onclick event. That is the cause of your problem. I don't know how to say it any more clearly than that.

Do you really need JavaScript to perform the submit? The simplest solution would be to simply remove the submit from your javascript.

Assuming you really do need JavaScript to do the sbumit, try this: If you couldn't get an onclick event to work for an <img> tag, try surrounding it with a hyperlink <a> stanza. Example:

[ July 09, 2007: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple form submission on single click on button
 
Similar Threads
how to call action on click of checkbox?
saving the data into database
display tag always doing the last action
display tag always doing the last action
Struts2: Server side response.....