Gerad Sioco
Gerad Sioco

Reputation: 1

Redirect to another page when ok clicked in confirm box

<a href ='create.php?monitor_id=$id' 
  onclick=if(confirm('really?')) return true; else return false;>
<center>DELETE</center></a>

I want to redirect my page to create.php when the user clicks ok in the confirm box, but this won't work. Any suggestions?

Upvotes: 0

Views: 4297

Answers (3)

djot
djot

Reputation: 2947

Use double quotes " in both attributes (href, onclick);

otherwise your $id get's not parsed in href; And the onclick does not work correctly without double quotes.

<a href="create.php?monitor_id=<?php echo $id; ?>" 
  onclick="if(confirm('really?')) return true; else return false;">
<center>DELETE</center></a>

Upvotes: 0

Ghanshyam Bhalala
Ghanshyam Bhalala

Reputation: 151

As you have specific url to redirect on click you have to write as follow

<a href ='create.php?monitor_id=$id' 
  onclick="doConfirm()">
<center>DELETE</center></a>

<script tyle="text/javascript">
    function doConfirm() {
         if(confirm('really?')) {
             window.location.href = "create.php?monitor_id=$id";
         }
         else {
             return false;
         }
    }
</script>

Upvotes: 0

Use double quotes to wrap your onclick()

onclick="if
        ^

Modified Code

<a href ='create.php?monitor_id=$id' onclick="if(confirm('really?')) return true; else return false;"><center>DELETE</center></a>

Upvotes: 1

Related Questions