Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-18-2002, 03:44 PM   PM User | #1
Hatch
New Coder

 
Join Date: Jun 2002
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Hatch is an unknown quantity at this point
Inserting multiple check boxes into DB

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
Hatch is offline   Reply With Quote
Old 07-18-2002, 06:51 PM   PM User | #2
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
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
QuackHead is offline   Reply With Quote
Old 07-18-2002, 08:56 PM   PM User | #3
Hatch
New Coder

 
Join Date: Jun 2002
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Hatch is an unknown quantity at this point
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 is offline   Reply With Quote
Old 07-19-2002, 03:22 PM   PM User | #4
allida77
Regular Coder

 
Join Date: Jun 2002
Location: Cincinnati, OH
Posts: 545
Thanks: 0
Thanked 0 Times in 0 Posts
allida77 is an unknown quantity at this point
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.
allida77 is offline   Reply With Quote
Old 07-19-2002, 06:21 PM   PM User | #5
QuackHead
Regular Coder

 
Join Date: Jun 2002
Posts: 344
Thanks: 0
Thanked 0 Times in 0 Posts
QuackHead is an unknown quantity at this point
Quote:
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

Last edited by QuackHead; 07-19-2002 at 06:32 PM..
QuackHead is offline   Reply With Quote
Old 07-24-2002, 08:09 PM   PM User | #6
RadarBob
Regular Coder

 
Join Date: Jun 2002
Location: Round Rock, Texas
Posts: 443
Thanks: 0
Thanked 0 Times in 0 Posts
RadarBob is an unknown quantity at this point
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:
Quote:
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.
RadarBob is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:51 PM.


Advertisement
Log in to turn off these ads.