Can I create a popup dialog box to confirm delete action?

Hi there,

I have created a delete button for my database, and I was wondering whether it was possible to create a script where a pop up information/dialog box would appear on screen to ask something like ‘Are you sure you want to delete?’ with Yes/No options, before the php delete script is actioned?

kemi

Yes, but this would be a javascript solution and not a php solution. There are many examples in the javascript forums for this, such as:

try this :
<a href=“” onclick=“return confirm('‘Are you sure you want to delete??’);”>delete</a>

this is the correct way, you can also pass PHP variables to it thus:


onClick=\\"return confirm('Are you SURE you want to delete {$row['name']}? ')\\"


Can I add a PHP variable to this code:


<script language='JavaScript'>

function validate()
{
	conf = confirm("Are you sure you want to delete?");
	if (conf)
		return true
	else
		return false;
}

</script>

I would like to add something like ‘Are you sure you want to delete $searchrace?’

Using your example, you would have a call something like this in your code:


echo("<input type='submit' onclick='return validate(\\'" . $searchrace . "\\');' />");

Then, in your javascript code, it would be:


function validate(race)
{
   conf = confirm("Show some text and the variable at the end..." + race);
}