Jump to content

how to exit if javascript code returns a value


solarisuser

Recommended Posts

Hello All,

I have incorporate a little javascript to show a confirm dialog box.  The problem I have is when the user clicks on the Cancel button (instead of the OK button), the page seems to do the URL transfer, but it still processes the rest of the PHP page.  I'd like to abort the page if the user clicks on cancel.

I put in an "exit(0);" like I would do in PHP, but it still processes the rest of the code.

One way I can think of getting around this is to set a variable like $abort to '1' after window.location(), but how do I get PHP to read the JS variable?

Thanks

Here is my code:
[code]
$sol = "testname";
if(isset($sol) && ($sol != '')) {
echo "
<SCRIPT type=\"text/javascript\">
<!--
hostname = '$hostname';
var answer = confirm (\"Your hostname is \"+hostname+\".  Is this correct?\")
if(!answer) { window.location = (\"index.php\"); exit(0); }
//-->
</script>
"; }
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.