<select> Default Value

This question already has an answer here:

  • How can I set the default value for an HTML <select> element? 18 answers

  • You don't use an argument $x of your Types function which as i guess is a selected value. Try to replace your function with this code:

    function Types($x) {    
        global $mysqli;
    
        $type = " SELECT type FROM types ";
    
        if ($type_results = $mysqli->query($type)) {
            while ($row = $type_results->fetch_assoc()) {
                $selected = ($row["type"] == $x) ? 'selected="selected"' : '';
                printf ("<option %s>%s</option>", $selected, $row["type"]);
            }
    
            $type_results->free();
        }    
    }
    

    and of course provide selected value to function Types in your html code.

    链接地址: http://www.djcxy.com/p/88076.html

    上一篇: 无法识别选择选项菜单的默认值

    下一篇: <select>默认值