• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Preventing submit of html:cancel using javascript

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use
> html:button value="Back" property="Back" onclic="return OnButtonClick();"<>/html:button<

This might work for you.

Regards
Infyniti.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic