Sander
Sander

Reputation: 73

Return confirm function does not work

I generate some buttons dynamically with php like this:

<?php
while( $row = mysql_fetch_assoc( $result ) ){
    echo "<tr>
        <td><a href='updateproject.php?id=$row[ID]' class='btn btn-warning btn-mini'>
            <i class='icon-white icon-pencil'></i>
            </a>
            <a href='deleterow.php?del=$row[ID]' onclick='return confirm('You want to delete this?');' class='btn btn-danger btn-mini'>
            <i class='icon-white icon-remove'></i>
            </a>
        </td>
        <td>{$row['Projectname']}</td>
        <td>{$row['Personincharge']}</td>
        <td>{$row['Description']}</td>
        <td>{$row['CreationDate']}</td>
        <td>{$row['Location']}</td>                             
    </tr>\n";
}
?>

I have tried so many things but it doesn't work. No alert is coming. It just getting deleted...

Upvotes: 0

Views: 864

Answers (3)

user3742456
user3742456

Reputation: 13

<script src="jquery.js"></script>
<script>
$(document).ready(function() {
        $('.delete').click(function(event){
    event.preventDefault();
    confirm('You want to delete this?');
    });
});

//db connection goes here

$query = mysql_query("Select * FROM `table_name`");

echo "<table>";
while( $row = mysql_fetch_assoc( $query ) ){

echo
"<tr>   
<td> <a href='deleterow.php?del={$row['id']}' class='delete'>Delete</a>
</td>
<td>{$row['Projectname']}</td>
    <td>{$row['Personincharge']}</td>
    <td>{$row['Description']}</td>
    <td>{$row['CreationDate']}</td>
    <td>{$row['Location']}</td>                      
</tr>\n";
}

echo "</table>";

Upvotes: 0

Robert
Robert

Reputation: 2282

I would encapsulate the table in a form and use the following code.

<form onsubmit=" return window.confirm('Are you sure?');">

  <?php
      //Add button php here and fields  
  ?>

</form>

Upvotes: 0

BenOfTheNorth
BenOfTheNorth

Reputation: 2872

Your slashes will be breaking as it'll think the statement ends at confirm('. Try this:

onclick=\"return confirm('You want to delete this?');\"

Upvotes: 2

Related Questions