Jump to content

[SOLVED] Javascript/PHP problem/query


s1yman

Recommended Posts

Hi,

 

I have a php page which when loaded will delete the reletive entry on the MYSQL DB table.

I wrote this js script as a last confirmation step before removing the file.

<script language="JavaScript" type="text/javascript">
{
doyou = confirm("Are you sure you want to delete this offer?"); //The question.
if (doyou == false)
history.go(-1); //If answered no, it sends you back 1 page)
} 
</script>

However, even if the user selects 'no' and gets sent back the php script has already loaded and therefore deleted the entry. Any ideas on how I can make this work the way intended?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/119148-solved-javascriptphp-problemquery/
Share on other sites

Simple answer. The javascript confirmation should be called BEFORE the delete script is loaded. That means, it must be called on the page that appears BEFORE the delete script. Try something like

 

<button onclick="if (confirm('Are you really really sure?')) window.location.href='delete_all.html'">delete everything</button>

 

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.