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

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!

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

how can i mark this as solved??? thanks dud.

how can i mark this as solved??? thanks dud.

Bottom-left, below the reply box.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.