Select option default based on database variable

前端 未结 1 1368
终归单人心
终归单人心 2020-12-22 09:43

I have a form, with a simple select box, and I also have a text field that pulls a value. I want to use the value in $Defaultselection as the default value for

相关标签:
1条回答
  • 2020-12-22 10:17

    That should do it:

    <select >
        <option value="1" <?php echo ($Defaultselection == 1)?"selected":""; ?>>A</option>
        <option value="2" <?php echo ($Defaultselection == 2)?"selected":""; ?>>B</option>
        <option value="3" <?php echo ($Defaultselection == 3)?"selected":""; ?>>C</option>
        <option value="4" <?php echo ($Defaultselection == 4)?"selected":""; ?>>D</option>
    </select> 
    

    or this other one:

    <select >
        <option value="1" <?php if ($Defaultselection == 1) echo "selected"; ?>>A</option>
        <option value="2" <?php if ($Defaultselection == 2) echo "selected"; ?>>B</option>
        <option value="3" <?php if ($Defaultselection == 3) echo "selected"; ?>>C</option>
        <option value="4" <?php if ($Defaultselection == 4) echo "selected"; ?>>D</option>
    </select> 
    
    0 讨论(0)
提交回复
热议问题