Reputation: 306
I have a really silly issue i am trying to sort out. I have made this script that displays and deletes users from a database. however my alert function is not working. it performs the action of deleting the content in the database regardless of what I press when the alert appears. here is my code:
<?php include_once "includes/scripts.php"; ?>
<?php include_once "includes/connect.php";?>
<?php include_once "includes/cms_page_security.php";?>
<div id="cms_container"><br>
<br>
<h1>MANAGE USERS<img src="images/three_column_grid_line.png" alt="line"></h1>
<p class="logout_btn"><a href="admin_cms.php">Back</a></p>
<?php
$tbl="users";
$sql = "SELECT * FROM users";
$result = mysql_query($sql, $connect);
while($rows = mysql_fetch_array($result)){
echo $rows['user_name'];
echo ' ';
echo $rows['user_id']
?>
<a href="includes/delete_user.php?user_id=<?php echo $rows['user_id'] ?>" onClick="alertFunction()">delete</a>
<?php
} mysql_close();
?>
<script>
function alertFunction()
{
var r=confirm("Do you want to delete this user?");
if (r==true)
{
}
else
{
return (false);
}
}
</script>
</div><!--cms_container-->
</body>
</html>
I would just like the alert function to stop then process of deleting the content when i press cancel.
Upvotes: 0
Views: 611
Reputation: 207900
Change:
onClick="alertFunction()"
to:
onClick="return alertFunction()"
and in the function itself, change the false return to return false;
. BTW, since a confirm returns true/false, you can change the first part of the condition to if (r)
Upvotes: 4