pdheady
asked on
javascript confirm function to control php/mysql row deletion
User clicks delete then i want to ask them if they are sure the want to delete the charge/row in database using javascript confirm function.
When I hit cancel it is still calling the php and deleting the data row.
How do i get this to work with javascript. Code below.
When I hit cancel it is still calling the php and deleting the data row.
How do i get this to work with javascript. Code below.
<?
if ($cmd == "delete_charge") { ?>
<script type="text/javascript">
var answer = confirm ("Are you sure you want to delete this charge?")
if (answer) {
<?
$sql = "
DELETE
from
charges
where charge_id = '" . $charge_id . "'
";
$rst = $con->execute($sql);
?>
} else {
window.location = "file.php?contact_id=<?=$contact_id?>"
}
</script>
<script type="text/javascript">
<!--
window.location = "file.php?contact_id=<?=$contact_id?>"
//-->
</script>
<?
}
?>
ASKER
no the popup works, for some reason whether i select ok or cancel both will call the php script.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thanks, i need to call the javascript function before i hit the script again.
ASKER
Thanks again.
Open in new window