I have a program that involves Javascript to allow for interaction with a webpage. It\'s a baseball site so what I am doing is prompting the user to enter a month. The user
While Pointy's answer is correct it does not explain why your code is not working. I'll try and explain:
The error is in this for
loop and how you are using innerHTML
.
for(var i = 0; i < schedule.length; i++)
{
document.getElementById("result").innerHTML = schedule[i] + "
";
}
Basically, on each iteration of the loop you are resetting the HTML of the result
element instead of appending to it. The following small change is all that would have been needed.
for(var i = 0; i < schedule.length; i++)
{
document.getElementById("result").innerHTML += schedule[i] + "
";
}
However, Pointy's answer is more efficient for sure.