Click to See Complete Forum and Search --> : [RESOLVED] passing value back from a confirmation on an alert box


perpetualshaun
12-23-2005, 09:17 AM
Here's my code:


...
<script language="JavaScript" type="text/javascript">
<!--
function alertBox () {
if(confirm("Are you SURE that you want to clear the CV2 value?\n\nIt will be erased... FOREVER")) {
return true;
} else {
return false;
}
}
-->
</script>
</head>
<body>
<?php
if(isset($_GET["clear"])) {
echo "clear: ".$_GET["clear"]."<br />\n";
}
?>
<a href="?clear=5" onClick="alertBox();">test</a>
</body>
....


I thought this would be very simple, but I've tried a number of things and just can't seem to get it to do what I want. I would like the link to return false / NOT WORK if they hit the cancel button. Any ideas?

Mr J
12-23-2005, 09:23 AM
Instead of

onClick="alertBox();"

try

onClick="return alertBox();"

Fang
12-23-2005, 09:25 AM
and function alertBox () {
return confirm("Are you SURE that you want to clear the CV2 value?\n\nIt will be erased... FOREVER");
}

Mr J
12-23-2005, 11:26 AM
I knew that return went somewhere :D :D :D