Jump to content


Photo

Dynamic Date Dropdown Box


  • Please log in to reply
4 replies to this topic

#1 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 03 March 2006 - 03:46 PM

ok, i would like to make a set of drop-down boxes where people can select the date
but say, if you selected March, the second dropdown box would automatically have 31 days
or if you selected April, there would only be 30

is this possible with php / how would i do it...

thanks in advance :)

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 03 March 2006 - 08:02 PM

Better to do something like this with javascript

<script>
        function daymenu(form, m) {
                 da = new Array(31,28,31,30);
                 n = form.day.options.length;
                    //clear array
                 for (var i=1; i <= n; i++) {
                      form.day.options[i] = null;
                 }
                    //add new values for new month

                 for (i=1; i <= da[m-1]; i++) {
                      form.day.options[i] = new Option(i, i, false);
                 }

        }
</SCRIPT>

<FORM>
      <SELECT  name='month' onChange='daymenu(this.form, this.value);'>

        <OPTION value=''>- Month -</OPTION>
        <OPTION value='1'>Jan</OPTION>
        <OPTION value='2'>Feb</OPTION>
        <OPTION value='3'>Mar</OPTION>
        <OPTION value='4'>Apr</OPTION>
        </SELECT>

        <SELECT  name='day'>
        <OPTION>-day-</OPTION>
        </SELECT>
</FORM>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 04 March 2006 - 12:27 PM

how would i do some sort of leap year detector, then it changes the february days

in thought something like

if(round((Year+1900)/4) != ((Year+1900)/4)){

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 04 March 2006 - 02:12 PM

Try

$febDays = date('t', mktime(0,0,0,2,1,date('Y')));

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 04 March 2006 - 05:07 PM

thanks!

*EDIT*
ah... i also have a year select so that means that the days in february will have to be dependant on that too :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users