0
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines

<script>
function del(delUrl) {
var r=confirm("Are you sure you want to delete?");
if (r==true)
{
alert("Deleted record!");
document.location = delUrl;
}
else
{
alert("Delete cancel!");
}
}
</script>
<a href='delete.php?id=$sysid' class='view' onClick='del()'>
<img src='image/vie.png' border='0'>
</a>

can someone tell where im wrong to this javascript...
this code pass the id=$sysid to the delete.php but before to pass i make dialogbox yes and no.
but this code alway sent me to the next page. help plsssss

2
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by DavidAntaramian
0

As I understand it, you currently have the following code:

<script>
    function del(delUrl) {
        var r = confirm("Are you sure you want to delete?");
        if (r == true) {
            alert ("Deleted record!");
            document.location = delUrl;
        } else {
            alert("Delete cancel!");
        }
    }
</script>

<a href='delete.php?id=$sysid' class='view' onClick='del()'>
    <img src='image/vie.png' border='0'>
</a>

The problem with this code is in the anchor tag. By defining an href, the link will execute the JavaScript defined in the onClick parameter, but it will also send you to the location defined in the href parameter regardless of your JavaScript. To fix this, set your href to #so that clicking on the link will not immediately send you to another location.

Now, you've already set up your JavaScript function to accept an argument with the location it is supposed to be navigating to on a positive response; you just didn't pass the function anything when using it. So, your onClick parameter needs to be set to del("delete.php?id=$sysid"). Your code should now look like the following:

<script>
    function del(delUrl) {
        var r = confirm("Are you sure you want to delete?");
        if (r == true) {
            alert ("Deleted record!");
            document.location = delUrl;
        } else {
            alert("Delete cancel!");
        }
    }
</script>

<a href='#' class='view' onClick='del("delete.php?id=$sysid")'>
    <img src='image/vie.png' border='0'>
</a>

I'd be happy to explain more if necessary. Otherwise, I hope this helps!

0

thanks men great help! really appreciated your effort for giving me ideal. keep it up :D thank you!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.