When someone clicks the Delete button, I want to show a confirmation dialog. Therefore I tried the following code:
(inside the HEAD tags)
<script language='JavaScript' type='text/JavaScript'>
function confirmAction(){
var confirmed = confirm("Are you sure? This will remove this entry forever.");
return confirmed;
}
</script>
And in the WHILE loop the following Hyperlink:
<a href='usermanager.php?delete=$userid' onClick='return confirmAction()'><img src='images/delete.png' /></a>
Now when someone clicks the link, a message will popup. The page reloads, the userid gets intercepted and the entry deleted. Just like it should.
But when someone has disabled Javascript in their browser, they won't see a message and the entry gets deleted instanty.
Therefore I changed it like this:
(in the head tags)
<script language='JavaScript' type='text/JavaScript'>
function confirmAction(userid){
var confirmed = confirm("Are you sure? This will remove this entry forever.");
if (confirmed) {
window.location = "usermanager.php?delete=" + userid
}
return confirmed;
}
</script>
And the WHILE loop
<a href='#' onClick='return confirmAction(".$userid_found .")'><img src='images/delete.png' /></a>
This works fine, basically people with Javascript disabled won't be able to delete it. In this scenario it adds 1 GET-tag to the URL.
But how would I add multiple GET-tags? Like search.php?term=$searchterm&value=$searchvalue? I tried putting in inside the enclosed tags like this:
<a href='#' onClick='return confirmAction('search.php?term=$searchterm&value=$searchvalue')'><img src='images/delete.png' /></a>
But in that case, nothing happens. I also tried turning the URL into a PHP variable, and then putting the variable inside the URL, but still Javascript doesn't accept it.
$url = "search.php?term=$searchterm&value=$searchvalue";
<a href='#' onClick='return confirmAction('$url')'><img src='images/delete.png' /></a>
How can I have Javascript accept such a URL?


Sign In
Create Account


Back to top









