File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Preventing submit of html:cancel using javascript

 
Charanjit Sidhu
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a small problem.. I have a button named 'Make Changes' on which I just want to use the browser back functionality. But I am not able to do it. The button is:

<html:cancel onClic="fnGoBac()" > Make Changes </html:cancel >

and the javascript code is:

function fnGoBack()
{
alet("In fnGoBack")
histori.go(-1)
}

(Note: history,onClick and alert are misspelled as histori,onClic and alet so that I can post this on this site.)
Onclick the alert appears but instead of going back to previous page, I get the page as defined by the action associated with this page.

However if I change the button code to normal html code (as shown below), it works fine.. but for consistency sake, I want to follow all sturts html
tags..

<input type="button" value="Make Changes" onclic="fnGoBack()" >

Please let me know how can I achieve this by using Struts HTML:Cancel or some other tag..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33703
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charanjit,
You want to use html:button instead of html:cancel. Struts' cancel button maps to a submit button. It then has all the characteristics of a submit button - submitting the page, doing an action, etc. On the other hand, html:button renders into the input button type that you used in the HTML code sample.
 
Anant Rao
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use
> html:button value="Back" property="Back" onclic="return OnButtonClick();"<>/html:button<

This might work for you.

Regards
Infyniti.
 
Kamesh Loganathan
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think that a more refined way of doing this is to use the html:cancel button, no java script and check for iscancelled in the action and fwd appropriately to the previous page.

Using javascripts history looks to be crude to me.
Correct me if i am wrong.
 
Charanjit Sidhu
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody for your responses.

I implemented the solution as suggested by Jeanne & Infyniti and it worked for me.

Kamlesh,
I just needed to show the previous screen with all the user's input in it. So I just used 'browser back functionality' for this purpose.
Actually I am learning Struts and didn't know how to repopulate the screen with same form data which had rows of input data having select and input boxes in each row. So I thought the quickest way will be to just do a 'Browser back'.

Thanks again!!
Charanjit
 
java_professional
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a better implementation of the cancel button. You can actually use EL and send a hidden field of ${header.Referer} which refers to the previous page and then submit the page to that value.
Hope this helps!
-K
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic