/    Sign up×
Community /Pin to ProfileBookmark

Trying to create a link that confirms

When the user clicks on an internal link, I want to call a JavaScript function that will display a confirmation message. I tried using the code below, but it didn’t work. Any ideas? Thanks.

[code]<a href=”javaxcript:void(0);” onclick=”javascript:return confirmExit(‘html_tables.html’)”>Tables</a>[/code]

I’m not sure that this code will work either. My JavaScript is pretty rusty.

[code]<script type=”text/javascript”>
function confirmExit(var link)
{
var reply = confirm(“Are you sure you want to quit this exam?nYour exam score will not be saved.”);
if (reply == true) {
window.location.href=”‘” + link + “‘”
}
return false
}
</script>[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@deep_dhyaniDec 22.2005 — <i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script Language="javascript"&gt;
function confirmExit(link)
{
var reply = confirm("Are you sure you want to quit this exam?nYour exam score will not be saved.");
if (reply) {
window.location.href="'" + link + "'";
}
}
&lt;/script&gt;
&lt;Body&gt;
&lt;a href="javascript:confirmExit('html_tables.html');"&gt;Tables&lt;/a&gt;
&lt;/Body&gt;
&lt;/head&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@JazzcatCBauthorDec 22.2005 — Nevermind, I found the solution.

Place part 1 code between the HEAD tags of your document.

Part 1 Code:

<SCRIPT LANGUAGE="Javascript">

<!---

function decision(message, url){

if(confirm(message)) location.href = url;

}

// --->

</SCRIPT>

Place part 2 code between the BODY tags of your document where ever you want the button displayed.

Change the text between the first set of single quotes to change the text displayed in the confirm window. Change the text between the second set of single quotes to change the URL that is loaded. Change the text before the </A> to change the link text.

Part 2 Code:

<A HREF="javascript:decision('Jumping to Crowder Associates Homepage!',

'http://www.crowderassoc.com')">HOT Web site!</A>[/quote]
Copy linkTweet thisAlerts:
@JazzcatCBauthorDec 22.2005 — deep.dhyani, thank you for your help. I didn't notice it in time, but I appreciate your effort.
×

Success!

Help @JazzcatCB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...