• 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

specify url in javascript function

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I generated a html page ( also can be a jsp page). In this page,I have a "CANCEL" button.
<form name=myForm>
<input type=button value="CANCEL" onClick="confirmit()">
</form>
What I want to do is when I click this button, a confirm window pops up, if I click "yes", a page in the specified url should be displayed,if I click "no", the current page should be displayed.
In the javascript,I implemented:
<script language="javascript">
function confirmit(){
if(!confirm("Are you sure you want to cancel? "))
//should stay with the current page , but don't know how to
//implement it.
else
//should go to a specified url, but don't know how to
//implement it.
}
</script>
Any suggestions? Tks!
Florence
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Florence,
You can do something like this.
<form name="myform">
<input type="button" onClick="confirmit()">
</form>
and write your function like this..
function confirmit()
{
if(confirm("Are you sure you want to cancel? "))
/////Specify the url here where you want to go.
{
document.myform.action="your url";
document.myform.submit();
}
}//end of function
Explanation:
if the user presses "Yes" in the confirm dialog box,then he's taken to the new page as described by "your url".Else if he presses "No" then simply nothing is done and your page stays where it is now.
Hope that helped.
Bunty
 
Florence Cheung
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,Bundy,
It works. Thank you very much!
Florence
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic