aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Problems with action Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Problems with action" Watch "Problems with action" New topic
Author

Problems with action

Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
Hi,

I have 2 buttons, one to save a page and one to cancel it.
When I hit the cancel button it should perform the "cancel" action but instead it does the action related to the save button

This is my code:

<input type="image" src="../images/button_save.gif" alt="save" title="Save taxonomy" accesskey="S"/>
<input type="image" src="../images/button_cancel.gif" alt="cancel" title="Cancel New Taxonomy" accesskey="C" oncclick="cancel()">

<script language="JavaScript">
function cancel()
{
document.forms[0].action="/nserverManager/sam/blank.do";
document.forms[0].submit();
}

</script>

Any ideas?

PD on purpose I wrote wrong the onclick method so I could post this message

thanks
[ October 25, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56150
    
  13

Are you saying that the blank.do action is not being invoked?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14669
    
  11

replace
<script type="JavaScript">
with
<script type="text/javascript">


[My Blog]
All roads lead to JavaRanch
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
yes,I'm saying that the blank.do action is not being invoked.

Satou I replaced the tag but didn't work...
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
try

onclick="cancel();return false;">

shot in the dark...

Eric
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
thanks a lot Eric...

can you tell me what does the "return false" do??
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
I think there is a race condition there and your function lost. The image is submitting before your code is run. So I had you cancel the image submit so your code would do the submission.

You probably could change it to be:

onclick="return cancel();">

AND

function cancel()
{
document.forms[0].action="/nserverManager/sam/blank.do";
return true;
}

and it probably will work.

Eric
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Problems with action
 
Similar Threads
Accelerator/Mnemonics
input type
jQuery not working on page
Require help in submitting <form> through JavaScript function
problems with form