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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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,

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.