Hello.
I have a problem when adding the javascript delete confirmation.
I use a page for both delete and update function.

The delete querystring is just like this :
adm_data.asp?act=del&id=6

And the update goes this way :
adm_data.asp?act=upd&id=6

I use this following code to processing delete:

If Request("act")="del" Then
Call Del() -----------------------> delete sub procedure
End If

I add this javascript confirmation ]

<SCRIPT LANGUAGE="JavaScript">
    function confirmDelete()
    {
    var agree=confirm("Are you sure to delete?");
    if (agree)
        return true;
    else
        return false;
    }     
</SCRIPT>

I include the onclick=confirmDelete() on the delete link which is located on side of each record that is shown.

When i click the delete link, the confirmation box appears. But even though i click the cancel button, the delete is still being executed.

I believe the problem is in the If Request("act")="del" Then*
Well any masters can help me solved the problem?
Any help will be apreciated.
Thanks....

Recommended Answers

All 7 Replies

Shouldn't it be Request.Querystring("act") ?

Yah that will do the same way to Request("act").
The problem is even i click the cancel button, the delete will still being executed.
It is easier if we can call sub procedure from javascript.
Such as :

<SCRIPT LANGUAGE="JavaScript">
function confirmDelete()
{
var agree=confirm("Are you sure to delete?");
if (agree)
return true;
call del();     else
return false;
}
</SCRIPT>

But that's impossible.

Can you help me aparnesh?
Thanks.

Why aren't you checking the confirmation before going to the delete page ? I presume in the page that offers both delete and update, you have 2 buttons for delete and update. So when the user clicks the delete button, check for confirmation and if yes, then call the deletepage with adm_data?act=del ... etc.
If you are using a Hyperlink(instead of the button) , then you might try having a confirmation page in between. Clicking on link takes to a page which seeks the confirmation. Clicking yes to the confirmation, sends to adm_data?act=del ... and clicking no returns to original page.

Hi there,

Use This function :

If you wanna use form

JavaScript :

<script type="text/javascript">
<!--//
function confirmation() 
    {
        var confirmMe= confirm("Do you really want to Delete??");
            if (confirmMe== true)
                {
                return true
                }
            else
                {
                alert("Action Aborted By User!")
                }
    } 
//-->
</script>

HTML :

<form action="" method="get" onSubmit="return confirmation()">
<input name="Submit" type="submit" value="Submit">
</form>

if you wanna use the link with Query string

JavaScript :

<script type="text/javascript">
<!--//
function confirmation1(url, act, id) 
    {
        var where_to_go= confirm("Do you really want to Delete??");
            if (where_to_go== true)
                {
                window.location=url+"?"+id+"&"+"act="+act;
                }
            else
                {
                alert("Action Aborted By User!")
                }
    } 
//-->
</script>

HTML :

<a href="#" onClick="confirmation1('/update.asp', 'update', 'id=<%=rs("id")%>')">Update Record</a>
<a href="#" onClick="confirmation1('/delete.asp', 'del', 'id=<%=rs("id")%>')">Delete Record</a>

Best Regards,
Rahul Dev Katarey

Hai Rahul.
Finally i had to separate the delete process into another page.
But i use your suggestion on the querystring.
It works.
But i have a little problem when i modified the code :

<a href="#" onClick="confirmation1('/delete.asp', 'del', 'id=<%=rs("id")%>')">Delete Record</a>

into this :

Response.Write "<a href='#' onclick='confirmation1('/delete.asp', 'del', 'id="&rs("id")&"')'>Delete</a></td>"

I use this code inside ASP delimiter. It should be ok.
But your original code works just fine, i need to know what's wrong with this.

Thanks Rahul.

Hi Again,

Problem is in the single quote (') ,double quote (")

Right syntax is this:

<a href="#" onClick="confirmation1('/delete.asp', 'del', 'id=<%=rs("id")%>')">Delete Record</a>

Output will be in HTML :

<a href='#' onclick="confirmation1('/delete.asp', 'del', 'id=1')">Delete</a>

But when you write with asp:

Response.Write "<a href='#' onclick='confirmation1('/delete.asp', 'del', 'id="&rs("id")&"')'>Delete</a>"

Output will be in HTML :

<a href='#' onclick='confirmation1('/delete.asp', 'del', 'id=1')'>Delete</a>

Therefore JavaScript Function Not Working

Regards,
Rahul

Hi,

I hope you problem already solved, if not so just write that in this way,

Response.Write "<a href=""" & "#" & """ onclick="& """confirmation1('/delete.asp', 'del', 'id="& rs("id") &"')""" & ">Delete</a>"

:)

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.