raj said:
hi there
I want to collect user input. I have a collection of 30 checkboxes that I
would like the user to pickout from. The information then will be recorded
to a database somehow. Finally the user will be allowed to change the
selection if required.
Which is the best way to do this. Do I need to create 30 different fields in
the database ?
Thanks
3 tables - one to hold user information, one to hold checkbox
information and one to join the two. So, if your checkboxes related to
colours, for example, the checkbox information table would be called
Colours. It would have an ColourID field and a ColourName field. To
write the checkboxes to the browser, you would select the records:
<%
sql="SELECT ColourID, ColourName FROM Colours"
set rs = conn.execute(sql)
if not rs.eof then
arrColours = rs.getrows
rs.close : set rs = nothing
for i = 0 to ubound(arrColours,2)
response.write "<input type='checkbox' name='colourid' value='"
& arrColours(0,i) & "'>"
response.write arrColours(1,i) & "<br>" & vbcrlf
next
else
response.write "no records"
rs.close : set rs = nothing
end if
%>
Once a user has made their selection, and you have caught their userid
in the form somewhere ( or querystring), on submission,
Request.Form("colourid") will hold a comma-delimited string of values.
This is where the 3rd table - UserColours comes into play. It has 2
fields - UserID and ColourID.
To process the comma-delimited string, do something like this:
<%
colours = Request.Form("ColourID")
colours = split(colours,",")
for i = 0 to ubound(colours)
conn.execute("Insert INTO UserColours (UserID, ColourID) VALUES ("
& userid & "," & colours(i) & ")")
next
%>
/P.