wood burning stoves
The moose likes HTML, CSS and JavaScript and the fly likes onClick event on Submit button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "onClick event on Submit button" Watch "onClick event on Submit button" New topic

onClick event on Submit button

Mohit Agarwal
Ranch Hand

Joined: Mar 30, 2004
Posts: 88

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() {
return false;

document.forms[o].action= .........;


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,
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
if you are using a submit button, you do not need to use:

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

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 ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: onClick event on Submit button
It's not a secret anymore!