Jump to content

MYSQL dynamic drop down with hidden value


studgate

Recommended Posts

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.

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

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.