Javascript confirmation box
by AcecoolWednesday, 23rd November 2005
This script shows you how to make a confirmation box that will take the user to a link if they click OK, or stay on the same page if they click cancel.
<script language="JavaScript">
<!--//
// First we make a function called ACMS_JavaScript_Confirm
// With the ability to input 2 pieces of data, Url and Text
function ACMS_JavaScript_Confirm(Url, Text) {
// Show the confirmation box with the input text.
Input_Data = confirm(Text);
// If the user clicks on the OK button
if (Input_Data == true)
{
// Redirect to the input URL / Else do nothing
document.location.href=Url
}
}
//-->
</script>
Now for the anchor. This tells the client that something will happen if they click the anchor, the href="#" is so if they press cancel, they will remain on the same page with a pound on the end.
If you do not use the href, it will still work but it wont look like a link:
<a onclick=""; href="#">
<a onclick="ACMS_JavaScript_Confirm('http://www.acecoolco.com/index.php', 'Are you sure you want to goto Acecoolco.com?')"; href="#">Visit Acecoolco.com</a>
So, onclick="Activate the javascript function in here, with the URL as the first input, and the text as the second."
© Acecool Company