Jump to content

Using javascript confirm


rondog

Recommended Posts

I have a list of items with a remove link next to them. When the user hits remove I want to do the javascript confirm. I have that part working from this:

echo "<tr class=\"first\"><td>$row[username]</td><td>$row[email]</td><td><a href=\"#\">Edit</a></td><td><a href=\"?remove&id=$row[id]\" onclick=\"confirmation('$row[id]','$row[username]')\">Remove</a></td></tr>";

 

the javascript function:

<script type="text/javascript">
function confirmation(id,name) {
var answer = confirm("Are you sure you want to remove: "+name+" from the database?")
if (answer){
	alert("you chose yes");
}else{
	alert("you chose cancel");
	return false;
}
}
</script>

 

The javascript function is working, however, if I hit cancel, it is still putting ?remove&id=id on my browser bar..I want it so it does nothing if they cancel. Maybe I am going about this wrong. Any tips?

Link to comment
https://forums.phpfreaks.com/topic/86599-using-javascript-confirm/
Share on other sites

try this:

 

 

<script type="text/javascript">
function confirmation(name) {
return confirm("Are you sure you want to remove: "+name+" from the database?");
}
</script>

<table>

<tr class="first"><td>username</td><td>email</td><td><a href="#">Edit</a></td><td><a href="?remove&id=123" onclick="return confirmation('username')">Remove</a></td></tr>

</table>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.