Jump to content

Dynamic Date Dropdown Box


Randy

Recommended Posts

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 :)
Link to comment
Share on other sites

Better to do something like this with javascript

[code]<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>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.