Jump to content

[SOLVED] How to include yes/no dialog box


marukochan

Recommended Posts

Hi!

 

How can I have a dialog box to confirm with the user whether he really wants to delete a specific record.

 

My code:

Here is where the user click the 'thrash' icon to delete a record.

.....

echo("<td width=15% align=middle><a href='admin_delete.php?id=".$row["project_id"]."'><img src='images/icon_delete.gif' border='0'></a>");

.....

So, before deleting the record I want to have a dialog box to confirm whether he wants to proceed with the deleting or not.

 

How can I do that ?

 

TQ

Link to comment
https://forums.phpfreaks.com/topic/42958-solved-how-to-include-yesno-dialog-box/
Share on other sites

How can I have a dialog box to confirm with the user whether he really wants to delete a specific record.

 

A true dialog box cannot be spawned from pure PHP.  It's a client-side action, so you need to use Javascript.  You could add an onclick attribute to the anchor tag for the delete link.  Something like this:

 

<a onclick="return confirm('Are you sure you want to delete this record?);" href="admin_delete.php?id=[...]

 

Please note that single-quoting attribute values is not XHTML-compliant.

Ferguser,

 

If I try to write this way within html, it is working

....

<td width=15% align=middle><a href="admin_delete.php?id="<? echo $row["project_id"]; ?>"" onClick="javascript:return confirm('Are you sure you want to delete this record?')"><img src='images/icon_delete.gif' border='0'></a>");

...

 

but when I wrote it this way within php, it is not working. I am so confused. How and when should I use single or double quoting. Can you correct my single and double quoting in this code?

 

....

echo("<td width=15% align=middle><a href='admin_delete.php?id=".$row["project_id"]."' onClick='javascript:return confirm('Are you sure you want to delete this record?')'><img src='images/icon_delete.gif' border='0'>[/a]");

....

 

....

echo '<td width=15% align=middle>';

echo '<a href="admin_delete.php?id='. $row["project_id"] .'" ';

echo 'onClick="javascript:return confirm(\'Are you sure you want to delete this record?\')">';

echo '<img src="images/icon_delete.gif" border="0">';

....

 

 

monk.e.boy

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.