Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to prompt for button press confirmation?

I’m loading data in to a html table using following function. It also creates a delete button in front of each row. I want to prompt user to either confirm or cancel. But the code does not work and it does not prompt for confirmation. Can someone show me how to do it properly?.

I use (onclick="return confirm(‘Are you sure?’)") to prompt.

 //This function will list categories  
 function listCategories($sqlString)
 {
    $result = mysqli_query($this->connectToDb(), $sqlString);

    if(mysqli_num_rows($result) > 0)
     {
         while ($row = mysqli_fetch_assoc($result))            
         {                
             echo "<tr>";
                echo "<td>".$row['cat_id']."</td>";
                echo "<td>".$row['it_category']."</td>";
                echo '<td>
                <form action="" method="POST">
                    <input type="hidden" name="catid" value="'.$row['cat_id'].'">
                    <input class="btn btn-outline-success" type="submit" name="Delete" value ="Delete" onclick="return confirm('Are you sure?')">
                </form>
                </td>'; 
             echo "</tr>";
         }
     }
 }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to escape the quotes around Are you sure. They’re matching the quotes around the string argument to echo.

                echo '<td>
                <form action="" method="POST">
                    <input type="hidden" name="catid" value="'.$row['cat_id'].'">
                    <input class="btn btn-outline-success" type="submit" name="Delete" value ="Delete" onclick="return confirm(\'Are you sure?\')">
                </form>
                </td>'; 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading