I have tried implementing onload into the containing div, and a lot of the code works fine when I execute individual pieces, but for some reason it will not load in its entirety even in jsfiddle:
https://jsfiddle.net/wf6gdr7z/1/
I still have a lot more to add to the code, I am more concerned with it executing so I can continue testing it and adding functionality. I have a feeling I am missing something really basic. :)
HTML
<div onload="businessYearlyHours()">
<h1>Business Hours</h1>
<p id="businessStatus"></p>
<p id="businessHours"></p>
<p id="otherNotes"></p>
<p>Only Service Animals are allowed in the business</p>
<p><a href="">Click here to see full hours for the year</a></p>
</div>
JAVASCRIPT
function businessYearlyHours() {
var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();
var hours = d.getHours();
var minutes = d.getMinutes();
var busHours;
var status;
if (month == 1 || month == 2 || month == 3){ // Jan 1 - Mar 31 Hours
busHours = "Jan 2-Mar 31: 9AM-5PM";
document.getElementById("businessHours").innerHTML = busHours;
if(month == 1 && day == 1){
otherNotes = "Closed Thanksgiving Day and Dec 24-Jan 1";
document.getElementById("otherNotes").innerHTML = otherNotes; // Display these additional notes on January 1st only
}
if (hours >= 9 && hours < 17){
status = "The Business is Open"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
else {
status = "The Business is Closed"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
}
else if (month == 4){ // April 1-30 Hours
busHours = "Apr 1-30: 9AM-7:30PM";
document.getElementById("businessHours").innerHTML = busHours;
if (hours >= 9 && (hours < 19 && minutes < 30)){
status = "The Business is Open"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
else {
status = "The Business is Closed"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
}
else if (month == 5 || month == 6 || month == 7 || month == 8){ // May 1 - Aug 31 Hours
busHours = "May 1-Aug 31: 9AM-9PM*";
otherNotes = "*On days when events are scheduled, business hours are 9AM-5PM";
document.getElementById("businessHours").innerHTML = busHours;
document.getElementById("otherNotes").innerHTML = otherNotes;
if (hours >= 9 && hours < 21){
status = "The Business is Open"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
else {
status = "The Business is Closed"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
}
else if (month == 9) { // Sep 1 - 30 Hours
busHours = "Sep 1-30: 9AM-7:30PM*";
otherNotes = "*On days when events are scheduled, business hours are 9AM-5PM";
document.getElementById("businessHours").innerHTML = busHours;
document.getElementById("otherNotes").innerHTML = otherNotes;
if (hours >= 9 && (hours >= 9 && (hours < 19 && minutes < 30)){
status = "The Business is Open"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
else {
status = "The Business is Closed"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
}
// Closed Thanksgiving Day / Christmas
else if ( month == 10 || month == 11 || month == 12) {
busHours = "Oct 1-Dec 23: 9AM-5PM";
otherNotes = "Closed Thanksgiving Day and Dec 24-Jan 1";
document.getElementById("businessHours").innerHTML = busHours;
document.getElementById("otherNotes").innerHTML = otherNotes;
if (hours >= 9 && hours < 17){
status = "The Business is Open"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
else {
status = "The Business is Closed"; // Consider making this status bold for each entry
document.getElementByID("businessStatus").innerHTML = status;
}
}
else () {
break;
}
}
<body onload=...>instead of<div onload=...>