deliriumxx
asked on
Can't process Checkbox in ASP
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"
On firstpage.asp I have
<input name="CheckToDelete<%=i%>"
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"
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"
ASKER
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.
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.
ASKER
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.
Var(i) = Request.Form("CheckBox" & i & "")
but I am using it in my sql statement so I need it here.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("CheckToDelet
IF VarChecked(i) = "on" THEN
Response.Write("Checked") %><br><%
Else
Response.Write("Unchecked"
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%>"
Checkbox 1<br>
<% next %>
</p>
<p>
<input name="submit" type="submit" value="Submit">
</p>
</form>
</body>
</html>