Jump to content

How do I get the value of this dynamic drop down list.


Racer2DQ

Recommended Posts

How do I get the selected value from a dynamic drop down list?

Here is my code to create the array:

    $products_size_array = array(array('id' => '', 'size' => '', 'sizecount' => ''));
    $products_size_query = tep_db_query("select products_id, products_size, products_sizecount from " . product_size . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' order by products_size");
    while ($products_size_detail = tep_db_fetch_array($products_size_query))
    {
    If ($products_size_detail['products_sizecount'] <> 0)
    $products_size_array[] = array('id' => $products_size_detail['products_id'],
                                          'size' => $products_size_detail['products_size'],
                                          'sizecount' => $products_size_detail['products_sizecount']
                                            );
    }

Here is the code to output the array as a drop down list:

                                    <SELECT name="size">
                                  <?php

                                  foreach ($products_size_array as $value)
                                  {
                                  If ($value[size] <>NULL)
                                        {
                                           
                                            echo "<OPTION value=\" $value[size] \">$value[size]</OPTION>\n";
   
                                        }
                                  }
                                 
                                  ?>
                                  </SELECT>


I have other fields in this form, so I need to get the value of the SELECTED value before submitting it and other field values.  I need something with an OnChange event to get the "size" selected.



Thank you all for your help.

You need to atleast name the field, and its easiest done with an array. eg;

[code=php:0]
echo "<OPTION name=\"youroptions[]\" value=\" $value[size] \">$value[size]</OPTION>\n";
[/code]

then, in php you will have an array contained within. $_POST['youroptions']. You could then loop through that array. eg;

[code=php:0]
foreach ($_POST['youroptions'] as $selected) {
  echo $selected;
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.