0

私のphp値がオプション値と等しい場合、そのオプション値を選択したいと思います。これはどのようにすればよいですか?

私がこのオプション値のセットを持っていると仮定します:

    <select id="updateBirthmonth" class="birth-date">
<?php $selected-value = 'May'; ?>
                    <option>Month:</option>
                    <option>January</option>
                    <option>February</option>
                    <option>March</option>
                    <option>April</option>
                    <option>May</option>
                    <option>June</option>
                    <option>July</option>
                    <option>August</option>
                    <option>October</option>
                    <option>November</option>
                    <option>December</option>
                </select>
4

1 に答える 1

1
Hey @Brained Washed option do have values.

$updateBirthmonth = $_REQUEST['updateBirthmonth'];

<select id="updateBirthmonth" class="birth-date">
    <option value="">Select Month</option>
    <option value="1" <?php if($updateBirthmonth=="1") { echo 'selected="selected"'; } else { echo ''; } ?>>January</option>
    <option value="2" <?php if($updateBirthmonth=="2") { echo 'selected="selected"'; } else { echo ''; } ?>>February</option>
    <option value="3" <?php if($updateBirthmonth=="3") { echo 'selected="selected"'; } else { echo ''; } ?>>March</option>
    <option value="4" <?php if($updateBirthmonth=="4") { echo 'selected="selected"'; } else { echo ''; } ?>>April</option>
    <option value="5" <?php if($updateBirthmonth=="5") { echo 'selected="selected"'; } else { echo ''; } ?>>May</option>
    <option value="6" <?php if($updateBirthmonth=="6") { echo 'selected="selected"'; } else { echo ''; } ?>>June</option>
    <option value="7" <?php if($updateBirthmonth=="7") { echo 'selected="selected"'; } else { echo ''; } ?>>July</option>
    <option value="8" <?php if($updateBirthmonth=="8") { echo 'selected="selected"'; } else { echo ''; } ?>>August</option>
    <option value="9" <?php if($updateBirthmonth=="9") { echo 'selected="selected"'; } else { echo ''; } ?>>September</option>
    <option value="10" <?php if($updateBirthmonth=="10") { echo 'selected="selected"'; } else { echo ''; } ?>>October</option>
    <option value="11" <?php if($updateBirthmonth=="11") { echo 'selected="selected"'; }  else { echo ''; } ?>>November</option>
    <option value="12" <?php if($updateBirthmonth=="12") { echo 'selected="selected"'; } else { echo ''; } ?>>December</option>
</select>

I hope this would help you. :)
于 2012-09-24T07:17:48.317 に答える