Can't process Checkbox in ASP

Posted on 2004-11-22
Last Modified: 2010-04-07
Here is the problem...

On firstpage.asp I have

<input name="CheckToDelete<%=i%>" type="checkbox" id="CheckToDelete<%=i%>" value="on">
in a loop that dinamicaly changes the checkbox name

On secondpage.asp I have

For i = 1 to NumVar
Redim VarChecked(i) = Request.Form("MyCheckBox" & i & "")

IF VarChecked(i) = "on" THEN
Response.Write("Checked") %><br><%
Response.Write("Unchecked") %><br><%

Why is this code completely non responsive.
What ever I do and no matter how I change the value and into what it simply remains "Unchecked"
Question by:deliriumxx
    LVL 48

    Expert Comment

    by:Ryan Chong
    >>Redim VarChecked(i) = Request.Form("MyCheckBox" & i & "")
    I think the syntax is wrong, and "MyCheckBox" should refer as "CheckToDelete"

    Try an example like below:

          NumVar = 10
          Redim VarChecked(NumVar)
          For i = 1 to NumVar
                VarChecked(i) = Request.Form("CheckToDelete" & i & "")
                IF VarChecked(i) = "on" THEN
                      Response.Write("Checked") %><br><%
                      Response.Write("Unchecked") %><br><%
                END IF


    <title>Untitled Document</title>

    <form name="form1" method="POST" action="">
       <% for i = 1 to 10 %>
        <input type="checkbox" name="CheckToDelete<%=i%>" value="on">
          Checkbox 1<br>
          <% next %>
        <input name="submit" type="submit" value="Submit">

    Author Comment

    No, the syntaks was right....
    I changed it here just to explain what I need but I didn't change it all, oooops, sorry.
    I am not a newbie in ASP,,, and that is all the more reason I was surprised with this thing. It has been a while since i used it in the extent I am using it now though.

    Anyway I solved the problem myself. Yesterday... Now I am deleting multiple records in a few lines of code.
    Apparently,,, when i asign the value to the checkbox dinamicaly (in the previous document),,, it is accepted and recognized on the page that does "request.form(key)".
    Loop format is realy not an issue here. In the example above I wasn't manipulating the database so it didn't matter (and I wasn't using dymamic database values).
    Here it matters.
    So this works like a charm..

           i = 0
           Rs.MoveFirst() // here is a record that I need permanently perserved for something
    Do While Not RS.EOF
           i = i + 1
           Redim Var(i)
          IF RS("PCode") = Request.Form("CheckBox" & i & "") THEN
                Var(i) = Request.Form("CheckBox" & i & "")
                RS_Manipulate.Execute SQLStatement
          END IF

    Thank you for a good will to try :)
    I sometimes post here because I get very fast responses and some great ideas come out of this form of communication.

    Author Comment

    This Line also doesn't serve the purpose of the example

    Var(i) = Request.Form("CheckBox" & i & "")

    but I am using it in my sql statement so I need it here.

    Accepted Solution

    PAQed with points refunded (50)

    Community Support Moderator

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Advanced Visual HTML Editor 2 69
    Show/hide areas of web form 10 60
    WEB Service vs ??? 7 82
    Problem to echo 6 29
    Now that Expression Web 4.0 ( is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
    This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
    The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: :…
    The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following:…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now