melati
melati

Reputation: 167

popup message before deleting data

I'm trying to put popup message in this code before user delete data. Here is my code.

while ($test = mysql_fetch_array($result))
{
    $id = $test['FailID'];

    echo "<tr align='center'>"; 
    echo"<td><font color='black'>" .$test['FailID']."</font></td>";
    echo"<td><font color='black'>" .$test['TajukFail']."</font></td>";
    echo"<td><font color='black'>". $test['JilidFail']. "</font></td>";
    echo"<td><font color='black'>". $test['StatusFail']. "</font></td>";    
    echo"<td> <a href ='daftarkemaskini.php?FailID=$id'>Edit</a>";
    echo"<td> <a href ='padamfail.php?FailID=$id'><center>Delete</center></a>";

    echo "</tr>";
}

but when I put it in there it doesnt work at all.

echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"

Can anyone help me on this?

Upvotes: 3

Views: 22592

Answers (7)

Shourabh Raja
Shourabh Raja

Reputation: 1

echo"<td><a href='delete.php?id={$row['id']}' onclick='return confirm_alert(this);' >Delete</a></td>"; **you should try this code ,it will definitely work **

=

<script>

//alert on delete

function confirm_alert(node) {

    return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");

}

</script>

<script>

//alert on delete

function confirm_alert(node) {

    return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");

}

</script>

hoping this will help you

Upvotes: 0

THE ONLY ONE
THE ONLY ONE

Reputation: 2190

Please the change the line

 echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"

to

echo "<td> <a href ='padamfail.php?FailID=$id' onClick='return confirm('are you sure you want to delete??');' ><center>Delete</center></a>";

Upvotes: 0

Rithu
Rithu

Reputation: 1289

<div class="third">
<input type="button" value="Remove" class="remve" name="<?php echo $row['choice_id']; ?>" onClick="deleteImage(<?php echo $row['choice_id']; ?>)"style="cursor:pointer;">
</div>


<script type="text/javascript">
function deleteImage(x){
var conf = confirm("Are you sure you want to delete this choice?");
if(conf == true){
window.location = "addnewentry/choiceRemove.php?id="+x;
}
}
</script>

Upvotes: 0

Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

You can try this--

echo "<td> <a href ='padamfail.php?FailID=$id' onClick=return confirm('are you sure you want to delete??');><center>Delete</center></;>";

Upvotes: 1

Michael
Michael

Reputation: 920

You need to escape the double quotes. Your code also had another syntax error at the end.

echo "<td> <a href='padamfail.php?FailID=$id' onClick=\"return 
confirm('are you sure you want to delete??');\"><center>Delete</center></a>";

Upvotes: 5

Richard Parnaby-King
Richard Parnaby-King

Reputation: 14891

You are putting javascript onclick code inside a double quote, which is being used to terminate the echo. Escape the double quotes:

echo"<td> <a href ='padamfail.php?FailID=$id' onClick=\"return confirm('are you sure you want to delete??');\"><center>Delete</center></a>"

Upvotes: 2

WannaKnow
WannaKnow

Reputation: 88

Try to escape the string:

echo "<td> <a href ='padamfail.php?FailID=$id' onClick=\"return confirm('are you sure you want to delete??');\"><center>Delete</center></";>"

Upvotes: 0

Related Questions