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 6987871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:59:41+00:00 2026-05-27T18:59:41+00:00

I would like a way to have a confirm box pop up when a

  • 0

I would like a way to have a confirm box pop up when a user clicks “delete” to remove a record.

Something like:

<script language="JavaScript"  type="text/javascript" >

function confirmDelete() {
    if(confirm("Would you like to delete the selected products?")) {
        <?php 
            $allCheckBoxId = $_POST['checkbox'];
            array_map ('mysql_real_escape_string', $allCheckBoxId);
            $ids = implode(",", $allCheckBoxId);
            $sql = "DELETE FROM products WHERE `id` IN ($ids)";
            mysql_query($sql);
        ?>
    }
}

</script>

With an onclick:

echo "<input type='submit' name='submit' value='Delete'  onclick='confirmDelete()' />";

But I know it’s not possible to be using Javascript & PHP together like this. Is there another way to do this? Maybe PHP has its own kind of confirm? Please give any ideas!

Thank you.

  • 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-27T18:59:42+00:00Added an answer on May 27, 2026 at 6:59 pm

    It is pretty easy to make use of AJAX for this case. Simply place your PHP in the scriptDelete.php file and make sure you pass the proper arguments and their values in the data property. For this example I just pass an id of 5.

    <script type="text/javascript">
    
        function confirmDelete() {
            if (confirm('Are you sure you want to delete this?')) {
                //Make ajax call
                $.ajax({
                    url: "scriptDelete.php",
                    type: "POST",
                    data: {id : 5},
                    dataType: "html", 
                    success: function() {
                        alert("It was succesfully deleted!");
                    }
                });
    
            }
        }
    </script>
    
    <input type='submit' name='submit' value='Delete'  onclick='return confirmDelete()' />
    

    Another way would be to post the form back to its own page like:

    <form method="post" action="yourpage.php">
        <input type="submit" name="submit" value="delete" onclick="return confirm('Are you sure you want to delete this?')" />
    </form>
    

    So you simply post the form back to yourpage.php and on top of this page you do something like:

    <?php
    
       //Means the form was submitted
       if ($_POST['submit']) {
          $id = $_POST['idToDelete'];
          $query = "DELETE FROM products WHERE id = " . mysql_real_escape_string($id);
          mysql_query($query) or die(mysql_error());
       }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found the way to copy the record that I would like, but
What would be the best way to accomplish something like this? Suppose I have
I have a double value f and would like a way to nudge it
I would like to temporarily override the kill-new function. I have a way I
I would like to know if there is a way in Android to have
I have a String which I would like to modify in some way. For
I have a problem and i would like to learn the correct way to
If I have a json like follows, what would be the most efficient way
I'm pretty sure no way but would like to check / confirm. I could
I would like a way to obtain an HTML element or CSS selector (or

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.