current date into dropdown boxes on load
Moderator: General Moderators
current date into dropdown boxes on load
i have three dropdown boxes, one for month, one for day and one for year, and what i want it to do is when the page loads the boxes are selected on the current date, but then you can easily change it if needed. how would i go about doing this?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
to go a bit furthur i would do something like this
edit.. ty for noticing quote fix
Code: Select all
<?
$selected_month = $_POST['month'];
$months = array_unique($selected_month, 'december','november','etc');
echo "<select name='select'>";
foreach ($months as $month)
{
echo '<option value="'.$month.'">$month</option>';
}
echo '</select>';
?>
Last edited by John Cartwright on Sun Oct 10, 2004 6:36 pm, edited 2 times in total.
so then if i have the month box,
then how would i incorporate something like echo date("m") into that?
Code: Select all
<select name="select">
<option value="1" selected>January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
you missed the point,
you put everything in an array, and then the duplicate month (your current month) will be eliminated and the current month will be the one at the top of the list.
note, you have an error on your first option
you put everything in an array, and then the duplicate month (your current month) will be eliminated and the current month will be the one at the top of the list.
note, you have an error on your first option
Last edited by John Cartwright on Sun Oct 10, 2004 6:38 pm, edited 1 time in total.