studgate Posted January 3, 2009 Share Posted January 3, 2009 Here is the code that I have, but I keep getting values out of the loop and more repeating values. I want to get the hidden value for each option. function dropdown( $name, array $options, $selected=null ) { /*** begin the select ***/ $dropdown = '<select name="'.$name.'" id="'.$name.'">'."\n"; $selected = $selected; /*** loop over the options ***/ foreach( $options as $key=>$option ) { /*** assign a selected value ***/ $select = $selected==$key ? ' selected' : null; /*** add each option to the dropdown ***/ $dropdown .= '<option value="'.$key.'"'.$select.'>'.$option.'</option>'."\n"; $dropdown .= '<input type="hidden" name="contact" value="'.$key.'">'."\n"; } /*** close the select ***/ $dropdown .= '</select>'."\n"; /*** and return the completed dropdown ***/ return $dropdown; } Please help, thanks in advance. Link to comment https://forums.phpfreaks.com/topic/139319-mysql-dynamic-drop-down-with-hidden-value/ Share on other sites More sharing options...
studgate Posted January 3, 2009 Author Share Posted January 3, 2009 Any suggestions??? I have one drop down menu and one form in the page, when the department selection is made I want to get the department id then echo some department details for the user, Here is an example: http://www.dreamfoundation.org/contact-us.html Link to comment https://forums.phpfreaks.com/topic/139319-mysql-dynamic-drop-down-with-hidden-value/#findComment-728762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.