/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] ‘null’ element … why?

I’m trying to determine the day (Sun-Sat) for any particular date in a mm/dd/yyyy selection.
In the following code, all works fine until it get to document.getElementById(‘dayInfo’).innerHTML = info.toDateString();

It does not appear to recognize the element <div id=”dayInfo”></div> as it give me an error that it is ‘null’

Can anyone see where I’m going wrong?
Nothing between the <div id=”dayInfo”> tags is showing up (or after for that matter) and it’s buggin’ the fool out of me!
Why am I getting a ‘null’ for this element reference?

[code]
<html>
<head>
<title>Special Times</title>
<script type=”text/javascript”>

function createMM() {
var MonthNames = [‘Jan’,’Feb’,’Mar’,’Apr’,’May’,’Jun’,’Jul’,’Aug’,’Sep’,’Oct’,’Nov’,’Dec’];
var str = ‘<select id=”mm” onblur=”checkHours()”>’;
for (var i=0; i<MonthNames.length; i++) {
str += ‘<option value=”‘+i+'”>’+MonthNames[i]+'</option>’;
}
return str;
}
function createDD() {
var str = ‘<select id=”dd” onblur=”checkHours()”>’;
for (var i=0; i<31; i++) {
str += ‘<option value=”‘+(i+1)+'”>’+(i+1)+'</option>’;
}
return str;
}
function createYY() {
var now = new Date();
var year = now.getFullYear();
var str = ‘<select id=”yy” onblur=”checkHours()”>’;
for (var i=(year-5); i<(year+25); i++) {
str += ‘<option value=”‘+i+'”>’+i+'</option>’;
}
return str;
}
function checkHours() {
var info = new Date(document.getElementById(‘yy’).value,
document.getElementById(‘mm’).value,
document.getElementById(‘dd’).value);
// alert(document.getElementById(‘dayInfo’).innerHTML);
document.getElementById(‘dayInfo’).innerHTML = info.toDateString();
}
</script>
</head>
<body onload=”checkHours()”>
mm/dd/yyyy
<script type=”text/javascript”>document.write(createMM()+’/’+createDD()+’/’+createYY());</script>
<div id=”dayInfo”>DAY of the date.</div>
What’s going on here???
</body>
</html>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMay 08.2009 — you aren't properly closing each select element. before returning the string add [b] str += '</select>';[/b] i'm pretty sure you now guess why it appear as null.
Copy linkTweet thisAlerts:
@JMRKERauthorMay 08.2009 — That was it ... now I feel really stupid. :o

Appreciate the look over my over look! ?
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...