Page 1 of 1

I am gettin fed up of date drop downs

Posted: Tue Dec 21, 2004 8:49 am
by andylyon87
Hey guys

this is real easy but I can't find the code anywhere and cannot remember how to do it.

All I need is the php code to make a drop down (select) box for the days in a month

Thanks
andy

Posted: Tue Dec 21, 2004 8:59 am
by pedrokas
<form name"blabla" method="" action"">
<select name="blabla">
<?

Code: Select all

for($i;$<32;$i++)
             &#123;
                 echo "<option>$i</option>";
             &#125;
?>
</select>
</form>

Posted: Tue Dec 21, 2004 9:42 am
by John Cartwright
You have to be carefully with dates, as each month has a different number of days, not to mention leap years.

I would create an array like

$days = array('December' => 31, 'November' => 30');

and loop through each month getting its value, and then plug it into that for loop.

Posted: Tue Dec 21, 2004 1:06 pm
by kenrbnsn
Do you want a drop down for a particular month? The current month? All the months in the current year? Or something else?

Here's the code for the current month, with the current day already selected:

Code: Select all

<?php
$td = date('j',strtotime('today'));
echo '<form method=post>'."\n";
echo date('F: ',strtotime('today'));
echo '<select name=dayofmonth size=1><option value=" "> </option>'."\n";
for ($d=1;$d<date('t',strtotime('today'))+1;$d++) {
    echo '<option value='.$d;
    if ($d == $td) echo ' selected ';
    echo '>'.$d.'</option>'."\n"; }
echo '</select>'."\n";
echo '<input type=submit name=submit value="Select Day"></form>';
echo '<hr>';
if (isset($_POST['submit'])) {
   echo '<pre>';print_r($_POST);echo '</pre>'; }
?>
The other solutions are left as an exercise for the original poster. :)

Posted: Wed Dec 22, 2004 1:05 pm
by andylyon87
thanks guys thats great, it makes things lots easier

Posted: Wed Dec 22, 2004 1:41 pm
by onion2k
I use this: http://www.softcomplex.com/products/tigra_calendar/ .. Its free, flexible, and works everywhere.

Posted: Wed Dec 22, 2004 1:50 pm
by kenrbnsn
onion2k wrote:I use this: http://www.softcomplex.com/products/tigra_calendar/ .. Its free, flexible, and works everywhere.
And it's Javascript... :( So if someone who has Javascript turned off accesses you site, they can't see your calendar.

Also, how do you know the original poster wanted a full blown calendar program?

Ken

Posted: Wed Dec 22, 2004 1:55 pm
by onion2k
kenrbnsn wrote:And it's Javascript... :( So if someone who has Javascript turned off accesses you site, they can't see your calendar.
They'll still see the input box for the date though, so the application will work fine. Client-side things are only an issue if they break functionality of a site when the client hasn't got scripting switched on.

As for him not requiring a full-blown calendar.. fair enough. I said I use it. I didn't say he has to.