Jump to content

display selected amount


runnerjp

Recommended Posts

i have this as to select dob

 

<select name="birthmonth" id="birthmonth">
            <?php

for($i = 1; $i <= 12; $i++)
{
    $selected = ($month==$i)?' selected="selected"':'';
    echo "<option value=\"0$i\"$selected>0$i</option>";
}
?>

        </select>
        <label for="birthday">Birth Day:</label>
        <select name="birthday" id="birthday">
            <?php
for($i = 1; $i <= 31; $i++)
{
    echo ($i < 10) ? '<option value="0'.$i.'">0'.$i.'</option>' : '<option value="'.$i.'">'.$i.'</option>';
}
?>
        </select>
        <label for="birthyear">Birth Year:</label>
        <select name="birthyear" id="birthyear">
            <?php
for($i = 1995; $i >= 1900; $i--)
{
    echo '<option value="'.$i.'">'.$i.'</option>';
}
?>

 

how i set it to display the already selected db by user?? i usually use something like

 

<select class="input" id="gender" name="gender"> 
<option value="Male" <?php if($gender == 'Male') echo 'selected'; ?>>Male</option>
<option value="Female"  <?php if($gender == 'Female') echo 'selected'; ?>>Female</option>
</select>

Link to comment
https://forums.phpfreaks.com/topic/99744-display-selected-amount/
Share on other sites

You need to set the value for $month

eg

<?php
$month = isset($_POST['birthmonth'])? $_POST['birthmonth'] : 0;

echo "<form method='post'>";
echo '<select name="birthmonth" id="birthmonth">';

for($i = 1; $i <= 12; $i++)
{
    $selected = ($month==$i)?' selected="selected"':'';
    printf ("<option value='%02d' %s>%02d</option>", $i, $selected, $i);
}
echo '</select>';
echo '<input type="submit" name="sub" value="Submit">';
echo '</form>'
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.