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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.