Racer2DQ Posted November 19, 2006 Share Posted November 19, 2006 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. Link to comment https://forums.phpfreaks.com/topic/27742-how-do-i-get-the-value-of-this-dynamic-drop-down-list/ Share on other sites More sharing options...
trq Posted November 19, 2006 Share Posted November 19, 2006 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] Link to comment https://forums.phpfreaks.com/topic/27742-how-do-i-get-the-value-of-this-dynamic-drop-down-list/#findComment-126916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.