• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple form submission on single click on button

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic