View Full Version : Javascript Error only in IE 6

05-06-2008, 03:44 PM
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)
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year

05-06-2008, 04:12 PM
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:
<body onload="populatedropdown('dayf','monthf','yearf')">
<select id="dayf"></select>
<select id="monthf"></select>
<select id="yearf"></select>
and I don't get any error in IE6. I wouldn't trust its line numbers.

05-06-2008, 04:57 PM
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:

05-06-2008, 05:14 PM
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 (http://tredosoft.com/Multiple_IE). I wonder if that may be the difference.

05-06-2008, 05:25 PM
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.

05-06-2008, 05:38 PM
Don't know the reason, but have a try by giving the src attribute to the script tag like

<script type="text/javascript" src="devotional.js">

//populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
populatedropdown("daydropdown", "monthdropdown")

PS: You have some markup errors too, see http://validator.w3.org/check?uri=http%3A%2F%2Fwww.crosst.org%2Ftest%2Findex.html&charset=%28detect+automatically%29&doctype=Inline&group=0
PPS: firebug says
yearfield has no properties
[Break on this error] yearfield.options[y]=new Option(thisyear, thisyear)

Arty Effem
05-06-2008, 06:39 PM
Link to the page:
The function expects three parameters, but is only being passed two:

populatedropdown("monthdropdown", "daydropdown")

05-06-2008, 07:41 PM
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>');