Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  188] [ 7]  / answers: 1 / hits: 57228  / 11 Years ago, thu, december 19, 2013, 12:00:00

I keep on getting the error Uncaught TypeError: Cannot set property 'innerHTML' of null when I try to run this program in chrome. I do not now what I am doing wrong, and and any help would be appreciated.



<!DOCTYPE html>
<html>
<head>
</head>
<script>
var x = hey;
var counter = 1;
var button = document.getElementById(button);
var div = document.getElementById(box);
var text = document.getElementById(text);
var sound = document.getElementById(sound);
var array=[ thanks for clicking, keep on clicking, click one more time, why do you keep on clicking me?, stop clicking me!];
function thing(file){
var y = array[Math.floor(Math.random() * array.length)];
if (x == y){
while (y == x){
var y = array[Math.floor(Math.random() * array.length)];
}
}
form1.text.value=y;

x = y;
sound.innerHTML = <embed src=+file+hidden=trueautostart=true loop=false/>;

}
</script>
</head>
<body>
<form name=form1>
<input type=button id=button value=click onClick=thing('sound.mp3') />
<input type=text id=text value=hey />
</form>
<div id=sound>
<p>
</p>
</div>
</body>
</html>

More From » html

 Answers
45

Wait for the window to load:



window.onload = function()
{
//yourJSCodeHERE
}


or move your JS after the </body> tag.


[#73646] Wednesday, December 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;