I don’t have much experience with JavaScript. However I wanted to do a small thing with JavaScript and MySQL. And I could use some help.
I have a page in PHP which search for something and it’s gives the results based on the search query.
For each result it adds 3 images, one which as a URL where you can view the content. Other where you can edit that content.
And the third one you can delete.
For that I wanted to do something nice.
Like, the user clicks the image, a confirmation dialog appears. In that box it asks if you sure you want to delete the data.
If yes, it would delete the data. where ID =
The ID is printed in the onclick action, inside the JavaScript function in the image using PHP echo.
If not, we would close the dialog and continue.
OK, so let’s assume the following (forgive me for re-clarifying the question):
You have a number of rows of some form, with delete links, and you want to confirm that the user actually wants to delete it?
Let’s assume the following HTML:
So I’m assuming the same PHP script can run the delete, picking up on the mode parameter:
I’m going to give two solutions to this on the JavaScript side – the first with an inline, slightly ugly solution, the second using jQuery (http://jquery.com/), and unobtrusive JavaScript.
Ok, so for the first, I would bind on the onclick event of each link.
Then create a JavaScript function:
As I said, I don’t like that solution, because it is horribly obtrusive, and also not particularly robust.
Now, the jQuery solution:
I heartily recommend this solution over the previous one, since it is much more elegant and nice, and is generally best practice.