PHP - PRE-select drop down option

前端 未结 3 447
渐次进展
渐次进展 2020-12-19 10:59

Using the example at the following URL: http://www.kavoir.com/2009/02/php-drop-down-list.html

How can I have that drop down menu pre-select one of the options such a

3条回答
  •  星月不相逢
    2020-12-19 11:36

    I would throw another parameter into the generateSelect function that defines what the default is. You can do this with either the id of the option or by the name. For the following, I'll use name to make it clearer.

    function generateSelect($name = '', $options = array(), $default = '') {
        $html = '';
        return $html;
    }
    
    /* And then call it like */
    $html = generateSelect('company', $companies, 'Apple');
    

提交回复
热议问题