Jump to content

Yes/No alert box. Php/Javascript


lopes_andre

Recommended Posts

Hi,

 

I need to do a Confirmation before delete some rows from the database. I think a alert box in javascript will do the job but I don't know how to start this...

 

I have a link like this:

 

<a href="url">Remove</a> 

 

How can I call the javascript code to deal with the Yes/No input from the user.

 

There are some tutorials that could help me? I'am a little bit lost.

 

Best Regards,

Link to comment
https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/
Share on other sites

Here's some basic js

 

function confirmDelete(id){

 

var response = confirm("Are you sure you want to delete this item?");

 

if (response){

window.location = "thefile.php?id=" + id + "&action=delete";

}

}

 

</script>

 

<input type="button" onclick="confirmDelete(34)" value="Delete" />

 

I would use Ajax for this, rather than the above code.

Hi, thanks for the reply.

 

One question. It is safe to pass the "id" in the function parameter. How can I prevent a user to change the parameter "id"? It is possible to change it?

 

How are you going to know what to delete if the ID isn't passed? If you are concerned about malicious users deleting records that shoulnd't be then you shoudll validate on the delete script that the user requesting the delete has the appropriate authorization to do so.

Thanks for all the reply's.

 

I have done it with Javascript, but it is ugly go to another page and then return to the last page.

 

My question. It is very dificult to do this task using ajax?

 

If I don't need to go to another page and then came back, better.

 

Best Regards,

 

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.