runnerjp Posted April 5, 2008 Share Posted April 5, 2008 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 More sharing options...
runnerjp Posted April 6, 2008 Author Share Posted April 6, 2008 bmp Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510379 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 you are already doing it for "birthmonth" Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510390 Share on other sites More sharing options...
runnerjp Posted April 6, 2008 Author Share Posted April 6, 2008 see i thought i was but it does not work just sets itself at 1 Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510392 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 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>' ?> Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510395 Share on other sites More sharing options...
runnerjp Posted April 6, 2008 Author Share Posted April 6, 2008 nope it still resets itself to 1 :S Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510396 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 The code I posted works. if you var_dump($month); what does it output? Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510398 Share on other sites More sharing options...
runnerjp Posted April 6, 2008 Author Share Posted April 6, 2008 Null Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510400 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 You need to set the value for $month Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510403 Share on other sites More sharing options...
runnerjp Posted April 6, 2008 Author Share Posted April 6, 2008 hummm im little confused here lol Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510405 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 $month needs to hold the value currently selected by the user; ie the value of the option that you want the select to display Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510409 Share on other sites More sharing options...
runnerjp Posted April 6, 2008 Author Share Posted April 6, 2008 ahhh ok i will get onto it ty Link to comment https://forums.phpfreaks.com/topic/99744-display-selected-amount/#findComment-510415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.