...

View Full Version : Inserting multiple check boxes into DB



Hatch
07-18-2002, 03:44 PM
I'm creating a shopping cart for bikes.
Depending on wich model of bike the users chooses dfferent parts populate check boxes for that particular model.
For example I choose model 1000.
I have a query that displays all part number for bike 1000
which looks like this

While
<input type=checkbox name=<% response.write objRS("PartNumber") %>value='on'>
Loop

<input type=checkbox name=102 value='on'>
<input type=checkbox name=741value='on'>
<input type=checkbox name=853value='on'>
<input type=checkbox name=965value='on'>

The user will check what parts he wants to order and press submit which will take them to addcart.asp.
Here is where my question comes in. How do I insert these part numbers into the database? I don't know what the partnumbers are cuz it populates itself. What value gets carried over?
Here is what I have tried in the addcart.asp

strSQL="select PartNumber from Bikes"
objRS.Open strSQL, objConn

PartNumber=request("ON")

objRS.movefirst
do until objRS.EOF
qryPartNumber = objRS("PartNumber")
if qryPartNumber = "PartNumber" then
response.write "Insert to DB"
end if
objRS.movenext
loop
But it does not work
Please Help
Thanks

QuackHead
07-18-2002, 06:51 PM
Ok, the reason it's ok working is because checkboxes pass a value of 'on' or no value at all (when unchecked)

Radio buttons will pass any value that you give them, so...

Change all the checkboxes to radio buttons, make sure they all have a different name, and set the value as the part number...

<input type="radio" name="102" value="102">
<input type="radio" name="741" value="741">
<input type="radio" name="853" value="853">
<input type="radio" name="965" value="965">


Let me know if that helps..

~Quack

Hatch
07-18-2002, 08:56 PM
Will you beable to click on more than one part with a radio button. and when I set it up like this how do I get the value from the next page (addcart.asp).
Would I do a request("Field") ??
I'm very new to asp. :)

allida77
07-19-2002, 03:22 PM
Give all the check boxes the same name.
Then all the values will be passed as a collection. Then iterate through the collection to update your db.

<input type=checkbox name=chkParts
value="102">
<input type=checkbox name=chkParts
value="201">
<input type=checkbox name=chkParts
value="187">
<input type=checkbox name=chkParts
value="311">

on your action page
Request.Form("chkParts")
if they are all checked they will return
102,201,187,311

Then just do a loop and update your db with these values.

QuackHead
07-19-2002, 06:21 PM
Originally posted by Hatch
Will you beable to click on more than one part with a radio button. and when I set it up like this how do I get the value from the next page (addcart.asp).
Would I do a request("Field") ??
I'm very new to asp. :)

Hatch...

As long as each radio button has a different name you can select as many as you want...

~Quack

RadarBob
07-24-2002, 08:09 PM
IMHO using radio buttons in this case goes against good interface design. Most users "know" that radio buttons are mutually exclusive as a set - only one of the whole set can be "on". Checkboxes, on the other hand, are designed for selecting "zero to many". Go with the flow. Don't turn this standard paradigm on it's head just because you can.

BTW, I just read the following in an ASP book:
When the browser submits the page, it only includes the values of radio buttons and check box controls which are actually set.

And of course, in true fashion of "look at this .. here's something else .. here's a tidbit... " books posing as tutorials and or references, nothing is said of SELECT controls.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum