Groups | Blog | Home
all groups > inetserver asp db > january 2007 >

inetserver asp db : I'm phuxored (complete ASP n00b) - Multiple checkboxes on a form?


ManningFan
1/19/2007 10:32:48 AM
I apologize for being a total n00b here, I'm pretty good with Access so
I understand some of the theory but I know little to nothing about ASP.

I want to create a form. On the form will be a question, something
like, "Which cars are your favorites?"

I want to put several checkboxes on the form and allow as many
selections as they want to check off.

I also want to put a text box where the user can leave comments, and
another where the put their name.

What's the best way to set up a table(s) so that I can store individual
responses to the form? How do I write the code if I'm going to do this
in ASP with an Access back end? Any help would be appreciated.
Mike Brind
1/19/2007 9:45:17 PM

[quoted text, click to view]

First, you will need to know enough about ASP and ADO so that you can
connect to a database and perform an insert operation. You will also need
to understand how an html form passes values either using POST or GET.
Finally, you will need to know how to retrieve the values from the posted
form.

www.w3schools.com/asp and www.w3schools.com/ado will get you started.
Another very good tutorial series can be found here:
http://msconline.maconstate.edu/tutorials/ASP/default.htm


--
Mike Brind

ManningFan
1/22/2007 7:53:15 AM
Well, I've done simple stuff connecting to DBs and spitting info out.
I just need to kno whow to store the value of a bunch of checkboxes and
keep it so that if more checkboxes are added in the future I can do it
through a table or something instead of having to edit the code.

[quoted text, click to view]
ManningFan
1/22/2007 9:03:16 AM
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, click to view]
Mike Brind
1/22/2007 4:38:33 PM

[quoted text, click to view]

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
database? If so, you use an Insert statement.

In terms of how you structure your table, that depends on what kind of
information you want to get out of it at the end.

--
Mike Brind

Mike Brind
1/22/2007 5:22:16 PM
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>


[quoted text, click to view]

Mike Brind
1/22/2007 5:35:24 PM
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


[quoted text, click to view]

AddThis Social Bookmark Button