Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

onClick event on Submit button

 
Mohit Agarwal
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am stuck in a issue , the problem seems to be more of java-script so i am
asking here.

I am using Struts .

In my page i had 2 submits . One for continuing the application & the other
one for saving & exiting from there.

1) html:submit value="continue
2) html:submit value="save" onklick="return save();"
The save() function is defined as :

function save() {
if(!validate())
return false;

document.forms[o].action= .........;
document.forms[0].submit();

}

The issue i am confronting is that the statements are executed twice which is evident from the fact that log messages are printing twice . I had checked the issue is not with the log levels.It is as if 2 threads are operating in tandem. As a result of which an exception is thrown.

However when i changed [html:submit value="save" onklick="return save();]
to [input type="button" onklick="save()" ], the problem seems to be off.

Please provide a reason for the same .

Thanks in advance,
Mohit.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using a submit button, you do not need to use:
document.forms[0].submit();

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The submit button has a lot of semantics of its own and its best not to try and compete with it with your own onclick handler. if you want to let the submit button do its own thing, don't use an onclick handler. Otherwise, use a vanilla (non-submit) button and handle things in your own way.
[ October 07, 2005: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic