Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic checkboxes

Status
Not open for further replies.

NevG

Programmer
Oct 10, 2000
162
GB
Hi people

Can someone advise as to the best direction to take on putting checkboxes on my page dynamically.

I can do the actual placing on the page using a loop. This is easy. The bit Im struggling with is how to post the checked check boxes to another form to do the database update.

I have my controls in a loop like this

do while not rs.eof
..
..
..
<TD><INPUT type=&quot;checkbox&quot; id=checkbox<%=i%> name=chkRSQuestion<%=i%>></TD>
..
loop


where i is a counter integer.

I will have several t once (10) on the screen and so how can I catch the checked boxes?


Thanks for any help
 
Hiya,

I did something like this with ColdFusion using the Evaluate function. I assume a similar function exists for ASP?

If so, this is how I did it:

After you're loop add a hidden field containing the value of i:
<input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;<%=i%>&quot;>

Then, at the page the parses the checkboxes you do the following (the example shows how to display them):

maxAmount = Request.Form(&quot;amount&quot;)
i = 1

do while i<= maxAmount
%>CheckBox<%=i%> = <%=
Replace the following line with whatever function ASP uses to do this
Evaluate(Request.Form(&quot;chkRSQuestion&quot;& i))
%><%
i=i+1
loop

Ofcourse, this example only works if there IS a equivalent of the Evaluate function. If there is, please post it in reply ok? If so, you'll have to adjust the code a bit to serve your needs.

The principle itself can be used anyhow.

Sure hope I got you any further? :p

Gtz,

Kristof
 
I am also having the same problem i.e. generating checkboxes dynamically and gettin the value in post.

I tried the above code in ASP.
is the syntax working for the line &quot;Request.Form(&quot;chkRSQuestion&quot;& i))&quot; ?
 
There is an eval function for ASP, but I think it is in ASP scripting version 5.0. See for more details.

To get by without using eval, if you name all the checkboxes the same, the value will be passed to the next page delimited with commas. You can pull the values out and put them in an array.

aryTemp = split(request.form(checkboxname),&quot;,&quot;)
'You can then pull the values using a for/next loop.

'get the number of items in your array
CounterStop = ubound(aryTemp)

for i = 0 to CounterStop
CheckboxValue= aryTemp(i)
Next


Joli
 
Thanks Joli

That code worked for me.
But I am trying to print some strings in the For loop while reading the arrray. Those don't work.
Here's the code:
count = ubound(tmpArray1)
For i = 0 to count
Response.Write tmpArray1(i)
Response.Write tmpArray2(i)
vflag = tmpArray1(i)
vid = tmpArray2(i)
sqlupdinvacct = &quot;Update tbl set flag = '&quot; & vacctflag & &quot;' ,&quot; where id = to_number('&quot; & vid &&quot;')&quot;
Response.Write sqlupdinvacct
'conn.execute(sqlupdinvacct)
Next


Cannot Print the sqlstmt. It prints both the values from the array.

Can anyone figure out why???
 
PLS igore the earlier message.
The problem is not in the code
It's the way Split treats unchecked checkboxes
 
Looked like you had an extra quote after the comma. Do you need the comma in your SQL statement?

sqlupdinvacct = &quot;Update tbl set flag = '&quot; & vacctflag & &quot;' , where id = to_number('&quot; & vid &&quot;')&quot;

Joli
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top