Jump to content

[SOLVED] Confirm Box?


ayok

Recommended Posts

Hi there,

 

I have a question regarding the confirm box of javascript. I'd like to pop up a confirm box when the admin wants to delete an item.

So when the person click on "ok", the item will be delete, but if "cancel" is clicked, then it would stay on this page. But I cannot get it works.

 

I've tried this script:

<script type="text/javascript">
function disp_confirm(){
    var name=confirm("You're going to delete this item, would you like to process it?")
    if (name==true){
        window.location("delete.php?id=$data[id_cat];")
    }
}
</script>

 

And this code on the delete:

<a href='' onclick='disp_confirm()'>delete</a>

 

Could anybody help me with this?

 

Thank you,

ayok

Link to comment
Share on other sites

<script type="text/javascript">

function disp_confirm(){

    var name=confirm("You're going to delete this item, would you like to process it?")

    if (name==true){

        window.location("delete.php?id=$data[id_cat];")

    }else{

      return true; // change true to false if it doesn't work

    }

}

</script>

Link to comment
Share on other sites

<script type="text/javascript">

function disp_confirm(){

    var name=confirm("You're going to delete this item, would you like to process it?")

    if (name==true){

        window.location("delete.php?id=$data[id_cat];")

    }else{

      return true; // change true to false if it doesn't work

    }

}

</script>

 

Hi thanks roopurt,

 

It is return to the page when i click "cancel", but it doesn't delete when i click on "ok".

Is there something wrong with the window location?

 

ayok

Link to comment
Share on other sites

It would be hard to say what's going on without seeing some more of your code.

 

Or you can try changing the line:

window.location("delete.php?id=$data[id_cat];")

to

window.location.href="http://www.yahoo.com/"

 

Just to make sure it's redirecting correctly when you press OK.

Link to comment
Share on other sites

Hi,

So far my javascript is:

function disp_confirm(){
    var name=confirm("Do you really want to delete this?")
    if (name==true){
        window.location("delete.php?id=$data[id_cat]")
    }
    else{
	return true;
	}
}

 

and the link where to click:

<a href='' onclick='disp_confirm()'>delete</a>

 

The confirm box is popuped but if i click on ok or cancel it will open the index page. Anybody can help me?

 

Thank you,

ayok

Link to comment
Share on other sites

<html>
<head>
<script type="text/javascript">
function disp_confirm(){
    var msg = "Do you really want to delete this?";
    if (confirm(msg)){
        window.location.href = "http://www.yahoo.com";
    }
    return false;
}
</script>
</head>
<body>
  <a href='' onclick='return disp_confirm();'>delete</a>
</body>
</html>

Link to comment
Share on other sites

<?php
$show = mysql_query("SELECT service.*,category.name FROM service LEFT JOIN category on service.category=category.id_cat WHERE category='$id'") or die(mysql_error());
echo "<table border=0><tr bgcolor='#D0DCE0'><th>Service</th><th>Description</th><th>Duration (minutes)</th><th>Prices</th></tr>";


    while (($data = mysql_fetch_array($tampil)) && (mysql_num_rows($tampil) > 0))
    {
        echo "<tr>";
        echo "<td bgcolor='#D47FFF'>$data[name_serv]</td>";
        echo "<td bgcolor='#FF55FF'>$data[desc_serv]</td>";
        echo "<td bgcolor='#D47FFF'>$data[minutes]</td>";
        echo "<td bgcolor='#FF55FF'>$data[price]</td>";
        echo "<td><a href='' onclick='disp_confirm()'>delete</a><br><a href=edit_service.php?id=$data[id_serv]>edit</a></td></tr>";
    }
    echo "</table>";
}?>

<script type="text/javascript">
function disp_confirm(){
    var msg = "Do you really want to delete this?";
    if (confirm(msg)){
        window.location("delete.php?id=$datakategori[id_cat]");
    }
    return false;
}
</script>

Link to comment
Share on other sites

Sorry, I missed some lines above it

 

<?php
$show1 = mysql_query("SELECT * FROM category WHERE id_cat='$id'") or die(mysql_error());
$datakategori = mysql_fetch_array($show1);
echo "<H3>$datakategori[name]</H3><br><img align='left' src='../pics/$datakategori[pic]'<br><H5>$datakategori[description](<a href=edit_cat.php?id=$datakategori[id_cat]>edit kategori</a> | <a href=add_cat.php>add kategori</a>)<H5>";

$show = mysql_query("SELECT service.*,category.name FROM service LEFT JOIN category on service.category=category.id_cat WHERE category='$id'") or die(mysql_error());
echo "<table border=0><tr bgcolor='#D0DCE0'><th>Service</th><th>Description</th><th>Duration (minutes)</th><th>Prices</th></tr>";


    while (($data = mysql_fetch_array($tampil)) && (mysql_num_rows($tampil) > 0))
    {
        echo "<tr>";
        echo "<td bgcolor='#D47FFF'>$data[name_serv]</td>";
        echo "<td bgcolor='#FF55FF'>$data[desc_serv]</td>";
        echo "<td bgcolor='#D47FFF'>$data[minutes]</td>";
        echo "<td bgcolor='#FF55FF'>$data[price]</td>";
        echo "<td><a href='' onclick='disp_confirm()'>delete</a><br><a href=edit_service.php?id=$data[id_serv]>edit</a></td></tr>";
    }
    echo "</table>";
}?>

<script type="text/javascript">
function disp_confirm(){
    var msg = "Do you really want to delete this?";
    if (confirm(msg)){
        window.location("delete.php?id=$datakategori[id_cat]");
    }
    return false;
}
</script>

Link to comment
Share on other sites

The problem is that you're trying to set the $_GET parameter in the Javascript but you are not in PHP mode (because you've stepped out of PHP with the ?>).

 

<script type="text/javascript">
function disp_confirm(){
    var msg = "Do you really want to delete this?";
    if (confirm(msg)){
        window.location.href = "delete.php?id=<?php echo $datakategori['id_cat'];?>";
    }
    return false;
}
</script>

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.