vbscript, msgbox, delete confirmation

A

Asif Rahman

Hi all!

Please improve on the following code to make sure the record gets deleted
only when the function returns false. Now I see the msgbox, but the record
gets deleted no matter the user clicks yes or no.

Thanks in advance.

Asif
=======================
Code:
<script language="VBScript">
Function confirmDelete()
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
confirmDelete = true
Else
confirmDelete = false
End If
End Function

</script>

<%
Response.Write "<a href=AprDelete.asp?ID=" & RS.Fields("ID") & "><img
src=images/delete.gif border=0 onClick = 'ConfirmDelete()'></a>"
%>
 
R

Roland Hall

in message
: Please improve on the following code to make sure the record gets deleted
: only when the function returns false. Now I see the msgbox, but the record
: gets deleted no matter the user clicks yes or no.
:
: Thanks in advance.
:
: Asif
: =======================
: Code:
: <script language="VBScript">
: Function confirmDelete()
: answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
: If answer = 6 Then
: confirmDelete = true
: Else
: confirmDelete = false
: End If
: End Function
:
: </script>
:
: <%
: Response.Write "<a href=AprDelete.asp?ID=" & RS.Fields("ID") & "><img
: src=images/delete.gif border=0 onClick = 'ConfirmDelete()'></a>"
: %>

Where do you tell it to delete the record? All you're showing is a DHTML
onclick event to validate a question to delete or not but where is the
delete routine code? Hopefully this is on an Intranet since you're using
client-side vbscript and language= is deprecated. type="text/vbscript"
should be used. Since this is an ASP NG, it would help to see the server
side code.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
A

Asif Rahman

Hi Roaland, Thanks.

Here's the code from the page (AprDelete.asp) that deletes the record:

<%
Dim DB
Set DB = server.CreateObject ("ADODB.Connection")
DB.Mode=3
DB.Open ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source= " +
"C:\database\corp.mdb")

DB.Execute ("Delete * from Appraised where ID=" & Request.QueryString("ID"))
%>

Asif.
 
M

Mark Schupp

Because you are not submitting a form returning false will not stop the
browser from going to the delete page.
Try:

<script language="VBScript">
Function confirmDelete( nID )
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
this.location = "aprdelete.asp?id=" & CStr(nID)
Else
confirmDelete = false
End If
End Function

</script>

<%
Response.Write "<a href=""javascript:confirmDelete(" & RS.Fields("ID") &
")"">" & _
<img src=""images/delete.gif"" border=""0"" ></a>"
%>

Also, you might want to get in the habit of using javascript for client-side
script in case your users decide to use a different browser.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top