Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date selector breaks on year - gotta be something simple?

Status
Not open for further replies.

lozkane

Technical User
Oct 10, 2010
3
0
0
thread216-1583849

I am following the script on this thread to get a date selector working. Works beautifully to populate the day field after but does not fill the year field options.

Can you see the error?

Firebug reports:
e is null
[Break On This Error] e.add(s);}}

This is the 'year' part of the script:
var y = 2010;
while (y-->1909){
var s = document.createElement('option');
var e = document.getElementById('year');
s.text=y;
s.value=y;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}

Thanks, laurie
 
Firebug reports:
e is null
[tt]var e = document.getElementById('year');[/tt] is returning null, not the DOM element you are expecting.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Ah, the old closing bracket stikes again! Both day and year were missing one. It's a nice date selector script:

function changeDate(i){
var e = document.getElementById('day');
while(e.length>0){
e.remove(e.length-1);
}
var j=-1;
if(i=="na")
day_count=0;
else if(i==2)
day_count=29;
else if(i==4||i==6||i==9||i==11)
day_count=30;
else
day_count=31;
while(j++<day_count){
var s=document.createElement('option');
var e=document.getElementById('day');
if(j==0){
s.text="Day";
s.value="na";
try{
e.add(s,null);}
catch(ex){
e.add(s);}}
else{
if(j<10){
j="0" + j;}
s.text=j;
s.value=j;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}}
var y = 2010;
while (y-->1909){
var s=document.createElement('option');
var e=document.getElementById('year');
s.text=y;
s.value=y;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top