rondog Posted January 18, 2008 Share Posted January 18, 2008 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 More sharing options...
pdkv2 Posted January 18, 2008 Share Posted January 18, 2008 Use echo "<tr class=\"first\"><td>$row[username]</td><td>$row[email]</td><td><a href=\"#\">Edit</a></td><td><a href='#' onclick=\"confirmation('$row[id]','$row[username]')\">Remove</a></td></tr>"; Rgds, Sharad Link to comment https://forums.phpfreaks.com/topic/86599-using-javascript-confirm/#findComment-442620 Share on other sites More sharing options...
phpQuestioner Posted January 18, 2008 Share Posted January 18, 2008 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 https://forums.phpfreaks.com/topic/86599-using-javascript-confirm/#findComment-442622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.