*
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
Author

onClick event on Submit button

Mohit Agarwal
Ranch Hand

Joined: Mar 30, 2004
Posts: 88
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
if you are using a submit button, you do not need to use:
document.forms[0].submit();

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onClick event on Submit button
 
Similar Threads
session management problem with iframes
validate form fields using javascript in struts
adding Dynamic text boxes using struts
conditional login.jsp
example for ImageButtonBean using DispatchAction class