469,339 Members | 8,437 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,339 developers. It's quick & easy.

vbscript, msgbox, delete confirmation

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>"
%>

Jul 22 '05 #1
3 13484
"Asif Rahman" wrote in message
news:uK****************@TK2MSFTNGP14.phx.gbl...
: 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
Jul 22 '05 #2
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.
"Roland Hall" <nobody@nowhere> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
"Asif Rahman" wrote in message
news:uK****************@TK2MSFTNGP14.phx.gbl...
: 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

Jul 22 '05 #3
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.

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

"Asif Rahman" <as**@email.com> wrote in message
news:uL****************@TK2MSFTNGP10.phx.gbl...
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.
"Roland Hall" <nobody@nowhere> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
"Asif Rahman" wrote in message
news:uK****************@TK2MSFTNGP14.phx.gbl...
: 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


Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by | last post: by
1 post views Thread by Vajrala Narendra | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.