Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 247403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:15:22+00:00 2026-05-11T21:15:22+00:00

I don’t have much experience with JavaScript. However I wanted to do a small

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:15:23+00:00Added an answer on May 11, 2026 at 9:15 pm

    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:

    <tr>
       <td>Some Item 1</td>
       <td><a href="?mode=delete&id=1" class="delete-link">Delete</a></td>
    </tr>
    <tr>
       <td>Some Item 2</td>
       <td><a href="?mode=delete&id=2" class="delete-link">Delete</a></td>
    </tr>
    <tr>
       <td>Some Item 3</td>
       <td><a href="?mode=delete&id=3" class="delete-link">Delete</a></td>
    </tr>
    

    So I’m assuming the same PHP script can run the delete, picking up on the mode parameter:

    <?php
        if($_GET['mode'] == 'delete') {
           //Check if there is something in $_GET['id'].
           if($_GET['id']) {
    
              //Prevent SQL injection, just to be safe.
              $query = "DELETE FROM sometable WHERE id='" . mysql_real_escape_string($_GET['id']) . "'";
    
              mysql_query($query);
           }
        }
    

    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.

    <tr>
       <td>Some Item 3</td>
       <td><a href="?mode=delete&id=3" class="delete-link" onclick="checkDeleteItem();">Delete</a></td>
    </tr>
    

    Then create a JavaScript function:

    //This will get called when the link is clicked.
    function checkDeleteItem() {
       //show the confirmation box
       return confirm('Are you sure you want to delete this?');
    }
    

    As I said, I don’t like that solution, because it is horribly obtrusive, and also not particularly robust.

    Now, the jQuery solution:

    //Do all this when the DOM is loaded
    $(function() {
       //get all delete links (Note the class I gave them in the HTML)
       $("a.delete-link").click(function() {
           //Basically, if confirm is true (OK button is pressed), then
           //the click event is permitted to continue, and the link will
           //be followed - however, if the cancel is pressed, the click event will be stopped here.
           return confirm("Are you sure you want to delete this?");
       });
    });
    

    I heartily recommend this solution over the previous one, since it is much more elegant and nice, and is generally best practice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the docs: The number of values in the IN… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer Better is a bit subjective / depends on your goals… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer In SQL Plus scripts you can use a substitution variable… May 11, 2026 at 11:44 pm

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I don't know when to add to a dataset a tableadapter or a query
I don't edit CSS very often, and almost every time I need to go
I don't understand where the extra bits are coming from in this article about
I don't want PHP errors to display /html, but I want them to display

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.