Link to home
Start Free TrialLog in
Avatar of pdheady
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.
<?
 
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>
 
 
<?
	
}
 
?>

Open in new window

Avatar of aldanch
aldanch
Flag of United States of America image

Line #6. Missing a semi-colon at the end?
var answer = confirm ("Are you sure you want to delete this charge?")

Open in new window

Avatar of pdheady
pdheady

ASKER

no the popup works, for some reason whether i select ok or cancel both will call the php script.
ASKER CERTIFIED SOLUTION
Avatar of alien109
alien109
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdheady

ASKER

ok thanks, i need to call the javascript function before i hit the script again.
Avatar of pdheady

ASKER

Thanks again.