lopes_andre Posted June 9, 2010 Share Posted June 9, 2010 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, Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/ Share on other sites More sharing options...
syed Posted June 9, 2010 Share Posted June 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1069942 Share on other sites More sharing options...
lopes_andre Posted June 10, 2010 Author Share Posted June 10, 2010 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? Best Regards, Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1070531 Share on other sites More sharing options...
Psycho Posted June 10, 2010 Share Posted June 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1070535 Share on other sites More sharing options...
jcbones Posted June 10, 2010 Share Posted June 10, 2010 You could also do it in a link. <a href="url?id=<?php echo $id; ?>" onclick"return confirm('Are you sure you wish to delete?');">Remove</a> Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1070544 Share on other sites More sharing options...
lopes_andre Posted June 11, 2010 Author Share Posted June 11, 2010 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, Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1070596 Share on other sites More sharing options...
trq Posted June 11, 2010 Share Posted June 11, 2010 It is very dificult to do this task using ajax? That completely depends on your ability, but it should be pretty straight forward. Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1070600 Share on other sites More sharing options...
jcbones Posted June 11, 2010 Share Posted June 11, 2010 I'll leave this as a note to the last question: Ajax Tutorial Quote Link to comment https://forums.phpfreaks.com/topic/204288-yesno-alert-box-phpjavascript/#findComment-1070611 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.