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>