Date dropdown not functioning

Discussion in 'Javascript' started by David, Oct 26, 2006.

  1. David

    David Guest

    I have a form on my asp page with 3 dropdowns, day, month & year, but
    for some reason, the day dropdown is displaying the 25th twice, instead
    of 26th, then 27th ?


    I have this script in the <head> of my asp page:

    _____________________

    <script type="text/javascript">

    var
    monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];

    function populatedropdown(dayfield, monthfield, yearfield){
    var today=new Date()
    var dayfield=document.getElementById(dayfield)
    var monthfield=document.getElementById(monthfield)
    var yearfield=document.getElementById(yearfield)
    for (var i=0; i<31; i++)
    dayfield.options=new Option(i+1, i+1)
    dayfield.options[today.getDate()]=new Option(today.getDate(),
    today.getDate(), true, true) //select today's day
    for (var m=0; m<12; m++)
    monthfield.options[m]=new Option(monthtext[m], monthtext[m])
    monthfield.options[today.getMonth()]=new
    Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true,
    true) //select today's month
    var thisyear=today.getFullYear()
    for (var y=0; y<20; y++){
    yearfield.options[y]=new Option(thisyear, thisyear)
    thisyear+=1
    }
    yearfield.options[0]=new Option(today.getFullYear(),
    today.getFullYear(), true, true) //select today's year
    }

    </script>

    _____________________________________


    I have this script in the Body of my asp page:

    <script type="text/javascript">

    //populatedropdown(id_of_day_select, id_of_month_select,
    id_of_year_select)
    window.onload=function(){
    populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
    }
    </script>

    ______________________________________

    I have this code in a form on my asp page:

    <select id="daydropdown">
    </select>
    <select id="monthdropdown">
    </select>
    <select id="yeardropdown">
    </select>


    ________________________________________

    PROBLEM: For some reason, instead of the daydropdown showing

    24
    25
    26
    27
    28

    it is displaying

    24
    25
    26
    26
    28

    Why is it not displaying the 27th day to select, i.e. tomorrow

    Appreciate any help you can offer me

    Thanks

    David
    David, Oct 26, 2006
    #1
    1. Advertising

  2. David

    Erwin Moller Guest

    David wrote:

    > I have a form on my asp page with 3 dropdowns, day, month & year, but
    > for some reason, the day dropdown is displaying the 25th twice, instead
    > of 26th, then 27th ?
    >
    >
    > I have this script in the <head> of my asp page:
    >
    > _____________________
    >
    > <script type="text/javascript">
    >
    > var
    >

    monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
    >
    > function populatedropdown(dayfield, monthfield, yearfield){
    > var today=new Date()
    > var dayfield=document.getElementById(dayfield)
    > var monthfield=document.getElementById(monthfield)
    > var yearfield=document.getElementById(yearfield)
    > for (var i=0; i<31; i++)
    > dayfield.options=new Option(i+1, i+1)
    > dayfield.options[today.getDate()]=new Option(today.getDate(),


    Here you add today again to the options.
    I think you wanted to select it instead of adding it again. :)
    I expect the same happens to year and month.

    Regards,
    Erwin Moller

    > today.getDate(), true, true) //select today's day
    > for (var m=0; m<12; m++)
    > monthfield.options[m]=new Option(monthtext[m], monthtext[m])
    > monthfield.options[today.getMonth()]=new
    > Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true,
    > true) //select today's month
    > var thisyear=today.getFullYear()
    > for (var y=0; y<20; y++){
    > yearfield.options[y]=new Option(thisyear, thisyear)
    > thisyear+=1
    > }
    > yearfield.options[0]=new Option(today.getFullYear(),
    > today.getFullYear(), true, true) //select today's year
    > }
    >
    > </script>
    >
    > _____________________________________
    >
    >
    > I have this script in the Body of my asp page:
    >
    > <script type="text/javascript">
    >
    > //populatedropdown(id_of_day_select, id_of_month_select,
    > id_of_year_select)
    > window.onload=function(){
    > populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
    > }
    > </script>
    >
    > ______________________________________
    >
    > I have this code in a form on my asp page:
    >
    > <select id="daydropdown">
    > </select>
    > <select id="monthdropdown">
    > </select>
    > <select id="yeardropdown">
    > </select>
    >
    >
    > ________________________________________
    >
    > PROBLEM: For some reason, instead of the daydropdown showing
    >
    > 24
    > 25
    > 26
    > 27
    > 28
    >
    > it is displaying
    >
    > 24
    > 25
    > 26
    > 26
    > 28
    >
    > Why is it not displaying the 27th day to select, i.e. tomorrow
    >
    > Appreciate any help you can offer me
    >
    > Thanks
    >
    > David
    Erwin Moller, Oct 26, 2006
    #2
    1. Advertising

  3. David

    David Guest

    Thanks for helping Erwin,

    Not being a Javascript wiz, what do I need to do to correct this ?

    Thanks so much

    David
    David, Oct 26, 2006
    #3
  4. David

    Erwin Moller Guest

    David wrote:

    > Thanks for helping Erwin,
    >
    > Not being a Javascript wiz, what do I need to do to correct this ?
    >
    > Thanks so much
    >
    > David


    Hi David,

    Just add them all, like you did, but remove the new Option for the one you
    want to select (today).
    Now make some aspcode that checks if the option you are adding is the one
    you want to select.

    Extend the syntax for a new option like this:
    new Option("text", value, defaultselected, selected)

    replace them with sensible values, in your case you want to write true for
    the defaultselected.

    Good luck,
    Erwin
    Erwin Moller, Oct 26, 2006
    #4
  5. David

    David Guest

    Erwin,

    I 've had a good look but JavaScript is like dutch to me, I cannot seem
    to grasp it :-(
    I got this code from the web and I am trying really hard to understand
    it .... maybe someday huh !

    I can kind of see what you are saying, but cannot fathom how to adjust
    the code.

    Oh well

    Thanks
    David, Oct 26, 2006
    #5
  6. In message <>, Thu,
    26 Oct 2006 06:57:56, David <> writes

    >I have a form on my asp page with 3 dropdowns, day, month & year,


    At first glance, it looks as if your code allows 31 days for every
    month.

    See <URL:http://www.merlyn.demon.co.uk/js-date6.htm#YMD>, but then read
    from the top of the page.

    It's a good idea to read the newsgroup and its FAQ. See below.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    <URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Oct 26, 2006
    #6
  7. David

    Erwin Moller Guest

    David wrote:

    >
    > Erwin,
    >
    > I 've had a good look but JavaScript is like dutch to me, I cannot seem
    > to grasp it :-(
    > I got this code from the web and I am trying really hard to understand
    > it .... maybe someday huh !
    >
    > I can kind of see what you are saying, but cannot fathom how to adjust
    > the code.
    >
    > Oh well
    >
    > Thanks


    Hi David,

    JavaScript is like Dutch to you?
    You are asking the wrong person for help then, since I AM dutch. :p

    Anyway, follow Stockton's advise and read the FAQ. It might help you
    understand the issue.

    Regards,
    Erwin Moller
    Erwin Moller, Oct 30, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sadf
    Replies:
    4
    Views:
    806
    Bob Carsto
    Nov 14, 2003
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    Enable property of a Panel not functioning

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Feb 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    348
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Feb 7, 2005
  3. surveyor04
    Replies:
    0
    Views:
    367
    surveyor04
    Feb 12, 2005
  4. Neo Geshel
    Replies:
    5
    Views:
    841
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Jun 14, 2005
  5. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,229
    Michael Borgwardt
    May 30, 2004
Loading...

Share This Page