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

    Dynamic Select Field?

    Hi there,

    I've run into a snag and would really appreciate some help!

    I have many colors/sizes of a particular product. Each item has a different SKU number, and each item has a different ProductID number.

    For example:

    ID Product Name ProductSKU Color Size
    3345 Product-A 24062-19 Green 8
    3346 Product-A 24062-20 Green 10
    3347 Product-A 24063-19 Red 8
    3348 Product-A 24063-20 Red 10

    The customer should only see the product once on the page, and then be able to select the color and size. I'm trying to figure out how to grab the correct SKU number depending on the color/size the customer chooses.

    I know I can use something like:
    PHP Code:
    <select name="color" onchange="this.form['product_no'].value=this.value">
    option>Select a Color...</option>
    option value="3345">Green</option>
    option value="3347">Red</option>
    But, you can see the problem. 3346 is also green, but just a different size. Is there a way to pull the correct id number upon selecting both the size *and* color?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Denver, Colorado USA
    Thanked 339 Times in 331 Posts
    I cannot offer any specific coding to do this, but here are some thoughts -

    Typically, to keep the form code generic, there would only be codes/values for the sizes and colors and these would be sent to the server when the form/order is submitted. The order processing code would determine the actual product ID/SKU...

    If you do want to do this in the browser, it would be possible to create a javascript function that is called using the onchange event that would look at the current color option selected and the current size option selected and determine the correct ID.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


    Posting Permissions

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