?
Solved

Can't process Checkbox in ASP

Posted on 2004-11-22
5
Medium Priority
?
171 Views
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><%
Else
Response.Write("Unchecked") %><br><%
END IF
NEXT

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"
0
Comment
Question by:deliriumxx
  • 2
4 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 12653483
>>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><%
            Else
                  Response.Write("Unchecked") %><br><%
            END IF
      NEXT

%>
<html>
<head>

<title>Untitled Document</title>
</head>

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

Author Comment

by:deliriumxx
ID: 12658353
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
       Rs.MoveNext()
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
       Rs.MoveNext()
Loop

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.
0
 

Author Comment

by:deliriumxx
ID: 12658381
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.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12860816
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
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: mywebsite.com/wp…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

864 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