populate dropdown from a php array

php

Posted on 30 Jan 15 by Vickey
  519



function arraySelectBox($id, $controlName='', $arrayToFill='', $selected='', $helpText='',$eventFunction='', $cssClass='', $makeDisable='')
{   

    if($controlName=='')
        $controlName = $id;

    if($cssClass!='')
        $cssClass = 'class=$cssClass';

    $selectBox .=  '<select name="$controlName">';
    if($helpText!='')
    $selectBox .= '<option value="0">$helpText</option>';
    else
    $selectBox .= '<option value="0">Select An Option</option>';
    foreach($arrayToFill as $key =&gt; $value)
    {
        if($selected==$key)

            $selectBox .= '<option selected="selected" value="$key">$value</option>';
        else
            $selectBox .= '<option value="$key">$value</option>';
    }

    $selectBox .= '</select>';
    return $selectBox;
}
arraySelectBox($id, $controlName='', $arrayToFill='', $selected='', $helpText='',$eventFunction='', $cssClass='', $makeDisable='');

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com