Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    344
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 07:32 PM.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •