Click to See Complete Forum and Search --> : Trying to create a link that confirms


JazzcatCB
12-21-2005, 08:01 PM
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.

<a href="javaxcript:void(0);" onclick="javascript:return confirmExit('html_tables.html')">Tables</a>

I'm not sure that this code will work either. My JavaScript is pretty rusty.
<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>

deep.dhyani
12-22-2005, 12:12 AM
<html>
<head>
<script Language="javascript">
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 + "'";
}
}
</script>
<Body>
<a href="javascript:confirmExit('html_tables.html');">Tables</a>
</Body>
</head>
</html>

JazzcatCB
12-22-2005, 12:54 AM
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>

JazzcatCB
12-22-2005, 12:56 AM
deep.dhyani, thank you for your help. I didn't notice it in time, but I appreciate your effort.