vbscript, msgbox, delete confirmation

Discussion in 'ASP General' started by Asif Rahman, Jan 12, 2005.

  1. Asif Rahman

    Asif Rahman Guest

    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>"
    %>
    Asif Rahman, Jan 12, 2005
    #1
    1. Advertising

  2. Asif Rahman

    Roland Hall Guest

    "Asif Rahman" wrote in message
    news:uKaJwvF%...
    : 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
    Roland Hall, Jan 12, 2005
    #2
    1. Advertising

  3. Asif Rahman

    Asif Rahman Guest

    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:%23rK8gVJ%...
    > "Asif Rahman" wrote in message
    > news:uKaJwvF%...
    > : 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
    >
    >
    Asif Rahman, Jan 12, 2005
    #3
  4. Asif Rahman

    Mark Schupp Guest

    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" <> wrote in message
    news:uLyjVHK%...
    > 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:%23rK8gVJ%...
    >> "Asif Rahman" wrote in message
    >> news:uKaJwvF%...
    >> : 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
    >>
    >>

    >
    >
    Mark Schupp, Jan 12, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sramruttun

    Re: delete confirmation in datagrid

    sramruttun, Jul 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    599
    sramruttun
    Jul 4, 2003
  2. Dotnet Guy

    Delete Confirmation

    Dotnet Guy, Oct 16, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    650
    Dwayne Wilkinson
    Oct 21, 2003
  3. Nedu N
    Replies:
    2
    Views:
    373
    Robert McLaws
    Dec 4, 2003
  4. Dave

    Delete confirmation

    Dave, Oct 3, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    446
    Craig
    Oct 4, 2004
  5. Bucky
    Replies:
    1
    Views:
    13,794
    Bucky
    May 19, 2005
Loading...

Share This Page