Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2003, 02:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Question on using the CONFIRM() method

On the current page that my user is on I am trying to confirm if the user, when he clicks on a given link, wants to set this current page as his home page or not. If he clicks OK he will proceed to the new page where the page is setup as his home page, however if he clicks CANCEL I need him to stay on the
page where he is at.

Right now if I click CANCEL he still proceeds to the
next page. What am I doing wrong? Any HELP would be appreciated. Thank you.

Here is the javascript code I am using:

<script>
function getConfirm()
{
var answer=confirm("When setting this feature, XXXZZZYYYY will
automatically launch the next and subsequent times that you long into CG.
To reset this feature, select the CG page that you would like to be your
start page and click on the 'Set this page as my CG Start Page'")
if (answer){
window.location="http://www.xxxyyyzzz.net/common/documents/set_home_page.asp?u="
& strU & "&sethomepage=xxxyyyzzz"
return true;
}
else{
return false;
}
}
</script>

Here is the vbscript where I am using this function:

Response.Write "<a href='/common/documents/set_home_page.asp?u=" & strU & "&sethomepage=xxxyyyzzz' onclick='getConfirm()'>Set XXXYYYZZZ to automatically launch upon logging into CG</a>.<br>"
 
Old September 4th, 2003, 02:24 PM
Authorized User
 
Join Date: Jul 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to stalker Send a message via MSN to stalker
Default

Can only help you with JScript, hope this help you out:

<html><head><title>Link confirm</title>

<script LANGUAGE="JScript">
    function makeSure(sURL) {
        if (confirm("Jump to "+sURL+"?")) { window.location = sURL; }
    }

    function callLink(strU) {
        tester.innerHTML = "<span style='font-family: arial; font-size: 12; cursor: hand;' onclick=\"makeSure('/common/documents/set_home_page.asp?u=" + strU + "&sethomepage=webpowerchart')\">Set Web PowerChart to automatically launch upon logging into CareGate</span>.";
    }
</script>

</head><body onload="callLink(34)">
    <div id="tester"></div>
</body></html>

 
Old September 4th, 2003, 02:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The fact that you are sent to the home page is not caused by the JavaScript. The function runs fine, and doesn't do anything when you click Cancel.

However, you'll need to change the href attribute of the tag. Even when you return false from the onclick function, the browser will still redirect the user to the page that is added to the href attribute. Use a # instead to create a null / void link:
Code:
Response.Write "<a href='#' 
onclick='getConfirm()'>Set XXXYYYZZZ to automatically launch upon 
logging into CG</a>.<br>"
You should use the window.location from your JavaScript to send the user to the next page.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old September 4th, 2003, 02:26 PM
Authorized User
 
Join Date: Jul 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to stalker Send a message via MSN to stalker
Default

I recommend spans.. but if you want to use links use this sintaxe:

<a href="javascript:YOURfunction()">text</a>


I cannot do it with VB coz I only know JScript

 
Old September 4th, 2003, 02:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks so much for your time and help. I will try them both.

Again thanks!!
 
Old September 11th, 2003, 10:34 AM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by savoym


<a href='/common/documents/set_home_page.asp?u=" & strU & "&sethomepage=xxxyyyzzz' onclick='getConfirm()'>Set XXXYYYZZZ to automatically launch upon logging into CG</a>.<br>
Your VBS is fine, so I removed it.

The problem is you're not processing the return value from getConfirm. The cleanest way to do this, one that will continue to work in browsers where JavaScript is disabled, is to change your anchor onClick to:
Code:
onclick='return getConfirm()'
This way, when getConfirm returns a "false", onClick will listen for it and not launch the link.

YMMV, but it shouldn't.

-EPC






Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about the clone() method ianni Java Basics 1 December 26th, 2007 05:14 AM
Question on RegExp exec() method jackhsu BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 2 June 7th, 2007 01:19 AM
SysCmd method question... cjudd VBScript 2 July 22nd, 2005 11:59 AM
Sort Method question rgalehouse Javascript 1 February 10th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.