Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Problems with check box and array

    I am building a simple message system for my intranet. I have a webpage where I see the name and subject of all messages received. Every name has a check box beside. What I want to do is that when I select some records using its check box, I want to send the values to a second page which will delete only the selected records. With the code I have right now, I can't only delete all records if I click all check boxes otherwise I receive an error message: " Subscript out of range: "

    This is the code I am using:

    Code:
    Dim strSQL
    Dim strID
    Dim strLD
    
    strID=Split(Request("mes_id"),",")
    strLD=Split(Request("mes_leido"),",")
    
    Dim Command1
    set Command1 = Server.CreateObject("ADODB.Connection")
    Command1.ConnectionString = MM_rentas_STRING
    Command1.Open
    
    Dim iLoop
    
    for iLoop=0 to Ubound(strID)
    If strLD(iLoop) = True then 'check to see if the check box is selected
    
    strSQL = "delete * from messages WHERE mes_Id = " & strID(iLoop)
    Command1.Execute strSQL
    
    end if
    Next
    
    Command1.Close
    Set Command1 = Nothing
    
    Response.redirect("message1.asp")
    I will appreciate any help about this matter.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Making it WAY too hard.

    Assuming that your <form> page with the checkboxes looks something like this:
    Code:
    <form method="post" action="deleteCheckedMessages.asp">
    <input type="checkbox" name="mes_id" value="777"/> From Ann to Bob</br>
    <input type="checkbox" name="mes_id" value="312"/> From Ann to Carl</br>
    <input type="checkbox" name="mes_id" value="133"/> From Ann to Doug</br>
    <input type="checkbox" name="mes_id" value="818"/> From Bob to Ann</br>
    <input type="checkbox" name="mes_id" value="773"/> From Doug to </br>
    
    <input type="submit" value="Delete checked messages"/>
    </form>
    Then your page named "deleteCheckedMessages.asp" can be as simple as this:
    Code:
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open MM_rentas_STRING
    
    strSQL = "DELETE from messages WHERE mes_Id IN ( 0, " & Request.Form("mes_id") & ")"
    conn.Execute strSQL
    Done.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thank you very much

    Thank you very much for your help.

    Sometimes, when you don't know about something you don't see it.

    God bless you.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •