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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.