Can you give me an example of the proper insert statement if I had 3
checkboxes on a form, chk1, chk2 and chk3?
> I'm not sure I understand what you mean by "how to store the value of a
> bunch of checkboxes". Do you mean how to insert a bunch of values in a
[quoted text clipped - 5 lines]
> --
> Mike Brind
Mike Brind - 22 Jan 2007 17:22 GMT
OK. The SQL will depend on how you structure your table. I guess at the
moment, you don't know the answer to that.
Let's say you have a question "Which of the following colours do you like?"
And you have a set of checkboxes representing the colour choices:
<input type="checkbox" name="colour" value="red"> Red <br>
<input type="checkbox" name="colour" value="red"> Red <br>
<input type="checkbox" name="colour" value="red"> Red <br>
<input type="checkbox" name="colour" value="red"> Red <br>
<input type="checkbox" name="colour" value="red"> Red <br>
> Can you give me an example of the proper insert statement if I had 3
> checkboxes on a form, chk1, chk2 and chk3?
[quoted text clipped - 8 lines]
>> --
>> Mike Brind
Mike Brind - 22 Jan 2007 17:35 GMT
Sorry about that - copying and pasting sent my post somehow....
Where was I? Oh yes...
OK. The SQL will depend on how you structure your table. I guess at the
moment, you don't know the answer to that.
Let's say you have a question "Q1. Which of the following colours do you
like?"
And you have a set of checkboxes representing the colour choices:
<input type="checkbox" name="Q1" value="red"> Red <br>
<input type="checkbox" name="Q1" value="blue"> Blue<br>
<input type="checkbox" name="Q1" value="green"> Green<br>
<input type="checkbox" name="Q1" value="brown"> Brown<br>
<input type="checkbox" name="Q1" value="orange"> Orange<br>
Because we gave the same name to each of the checkboxes, this grouped them,
and any values will be sent as a comma-separated string, so when someone
ticks Red and Green, what gets passed in the Request collection is a
name/value pair is:
name = Q1
value = Red,Green
If you are happy to store "Red,Green" in the field for Q1, then the Insert
statement is straightforward:
Insert into Questions (Q1) Values ('" & Request.Form("Q1") & "')
However, if the person answering the questions missed Q1, then
Request.Form("Q1") will not exist. Checkbox values are only passed if they
are selected. You can test the length of the value to see if there is
anything there:
If Len(Request.Form("Q1")) = 0 'then you know it wasn't answered.
You need to think a bit more about what information you want to store then
have a go at doing it. If and when you run into problems or get error
messages, come back with the code you tried and a description of the
problem.
--
Mike Brind
> Can you give me an example of the proper insert statement if I had 3
> checkboxes on a form, chk1, chk2 and chk3?
[quoted text clipped - 8 lines]
>> --
>> Mike Brind