Problem when adding delete confirmation

Thread Solved

Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Problem when adding delete confirmation

 
0
  #1
Apr 28th, 2007
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....
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 188
Reputation: aparnesh is an unknown quantity at this point 
Solved Threads: 10
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: Problem when adding delete confirmation

 
0
  #2
Apr 29th, 2007
Shouldn't it be Request.Querystring("act") ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Re: Problem when adding delete confirmation

 
0
  #3
Apr 30th, 2007
Originally Posted by aparnesh View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 188
Reputation: aparnesh is an unknown quantity at this point 
Solved Threads: 10
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: Problem when adding delete confirmation

 
0
  #4
Apr 30th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Problem when adding delete confirmation

 
0
  #5
May 5th, 2007
Hi there,

Use This function :

If you wanna use form

JavaScript :

  1. <script type="text/javascript">
  2. <!--//
  3. function confirmation()
  4. {
  5. var confirmMe= confirm("Do you really want to Delete??");
  6. if (confirmMe== true)
  7. {
  8. return true
  9. }
  10. else
  11. {
  12. alert("Action Aborted By User!")
  13. }
  14. }
  15. //-->
  16. </script>
HTML :
[html]<form action="" method="get" onSubmit="return confirmation()">
<input name="Submit" type="submit" value="Submit">
</form>
[/html]

if you wanna use the link with Query string

JavaScript :

  1. <script type="text/javascript">
  2. <!--//
  3. function confirmation1(url, act, id)
  4. {
  5. var where_to_go= confirm("Do you really want to Delete??");
  6. if (where_to_go== true)
  7. {
  8. window.location=url+"?"+id+"&"+"act="+act;
  9. }
  10. else
  11. {
  12. alert("Action Aborted By User!")
  13. }
  14. }
  15. //-->
  16. </script>
HTML :

[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>[/html]
Best Regards,
Rahul Dev Katarey
Last edited by katarey; May 5th, 2007 at 5:16 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Re: Problem when adding delete confirmation

 
0
  #6
May 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Problem when adding delete confirmation

 
0
  #7
May 6th, 2007
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
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Problem when adding delete confirmation

 
0
  #8
May 23rd, 2007
Hi,

I hope you problem already solved, if not so just write that in this way,
  1. Response.Write "<a href=""" & "#" & """ onclick="& """confirmation1('/delete.asp', 'del', 'id="& rs("id") &"')""" & ">Delete</a>"
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC