Hello all, it's me again 😃
I'm trying to make a drop down menu that will have the options for the Date, Month, Year, 5 years ahead would be great...
Only thing is, I have no clue how...
I would really appreciate it if someone could help?
Thanks. 🙂
Plug this into your HTML page. I just inserted the first few days and months, I 'm sure you can figure it out.
<form name="form1" method="post" action=""> <select name="select"> <option>Months:</option> <option value="Jan">Jan</option> <option value="Feb">Feb</option> <option value="March">March</option> </select> <select name="select2"> <option>Days:</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> </select> <select name="select3"> <option>Year:</option> <option value="2002">2002</option> <option value="2003">2003</option> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> </select> </form>
yeah, I thought of doing it like that, but the trouble is that certain months have more or less days in them, which is really bloody annoying.
There must be an easier way. 🙁
Thanks for your suggestion though. 🙂
Well you can just do 31 days and hope the people using it are smart enough to know which one to pick. And you can always use datecheck() on the date they give to make sure it is valid.
I am not very knowledgable about javascript but you could probably use it to create the days pop-up on the fly when the user selects the month. I have seen stuff like this around where the option in one popup menu are changed based on the options in a previous menu.
The problem with using PHP for something like this is that it is a pre-processor. If it could be used like javascript (as the user is viewing and working with the page) then it would be easy enough to do this with it.
Yeah i was thinking of using checkdate(); but I changed the field to a text box and i was wondering weather the function could still be used even with 21/12/2002 type date with the slashes?
I made a loop which would create the options 12 times for the months and another one for the year. But now I need to do one for the days of the month.
I know there are functions for this like mcal_days_in_month(); But they are not installed on my host, so I'm not sure how to do it. Someone told me to use a switch statment... But I don't know how.
Can anyone help? All I need to do is find the last integer day of any given month.
Yeah a switch statement would be what you want.
switch ($month){ case Jan: $daysinmonth = 31; break; case Feb: $daysinmonth = 28; break; }
ect ect
Of course you should also toss in a leap year check. Only problem is using this in a form the PHP doesn't know what the month is until the user selects it and because the way PHP works (processing the script before outputting to the browser) it won't be able to generate a days popup for anything except the one you default to if they are on the same page. Now then you can do this with javascript so that when they select the month it will edit the popup menu as the user selects the month instead of when the page is loading but I don't know how.
Why not simply use an array ?
$number_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);