Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    43
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Javascript Error only in IE 6

    IE 6 is returning the error: "object required" for line 59, which I believe is
    the line "yearfield.options[y]=new Option(thisyear, thisyear) " in the code listed below. This script displays the current month and day of the month each in their own pulldown form input. Except in IE 6 where I am getting the error. Any Ideas? Thanks!


    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[i]=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
    }

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    The top sticky post in this forum has useful advice for getting a helpful response. Specifically, the subject itself recommends wrapping code in appropriate tags.

    I used your exact code with only this as the body:
    Code:
    <body onload="populatedropdown('dayf','monthf','yearf')">
    <select id="dayf"></select>
    <select id="monthf"></select>
    <select id="yearf"></select>
    </body>
    and I don't get any error in IE6. I wouldn't trust its line numbers.

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    43
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for looking into it though. Can you see anything that would cause it to display the wrong month and day of the month? It's supposed to get todays month and day and load that into the form pulldown, but in IE 6 it is loading in Dec 24th? Any Ideas? Thanks Again!

    Link to the page:
    http://www.crosst.org/test/index.html

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Actually, I get May 6 when I go there.

    Do you have a separate machine for testing with IE6? I'm not using a "pure" IE6, but am rather testing with MultipleIE. I wonder if that may be the difference.

  • Users who have thanked tomws for this post:

    svoltmer (05-06-2008)

  • #5
    New Coder
    Join Date
    Sep 2004
    Posts
    43
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I am such a moron. I am testing it on another machine, but I failed to look at it's "Time and Date settings". They were wrong. Sorry to bother you. IE 6 still says that there is an error on the page though. Can't tell what it is. Thanks for your time.

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Don't know the reason, but have a try by giving the src attribute to the script tag like
    Code:
    <script type="text/javascript" src="devotional.js">
    
    //populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
    window.onload=function(){
    populatedropdown("daydropdown", "monthdropdown")
    }
    </script>
    PS: You have some markup errors too, see http://validator.w3.org/check?uri=ht...Inline&group=0
    PPS: firebug says
    yearfield has no properties
    [Break on this error] yearfield.options[y]=new Option(thisyear, thisyear)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by svoltmer View Post
    The function expects three parameters, but is only being passed two:
    Code:
    window.onload=function(){
    populatedropdown("monthdropdown", "daydropdown")
    }

  • Users who have thanked Arty Effem for this post:

    svoltmer (05-06-2008)

  • #8
    New Coder
    Join Date
    Sep 2004
    Posts
    43
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Adding the src for that takes the pulldowns that were populated out (blanks them).

    Different subject...

    how would I write the syntax to place all the scripting for the pulldowns on an external .js file? Here is what I have, but it is not correct and won't display the pulldowns. I am sure it is just my syntax. Can you help? Thanks!

    <!-- devotional -->

    document.write('<form class="devotion" action="" name="someform"><select id="monthdropdown"><\/select><select id="daydropdown"><\/select><\/form><button style="margin-top:8px; padding:2px 3px 2px 3px;width:auto; height:auto; text-align:center;" onclick="document.location=('http:www.crosst.org/devotional/' + document.getElementById('monthdropdown').value + document.getElementById('daydropdown').value + '.html');">GO<\/button><script type='text/javascript' src='devotional.js'> window.onload=function(){populatedropdown("monthdropdown", "daydropdown")}<\/script>');

    <!-- Book of the Month -->

    document.write('<div class="tab_botm">Book of The Month<\/div>');


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •