So I gave seen the same error message presented many times on this site but the problem is always the script loading before the html, but in my case the script is linked at the end of the html. But I keep getting this error message in the console "Cannot set property 'innerHTML' of null" and have been trouble shooting for a while and was unable to locate the issue.
HTML
<select id="selectCon" onchange="contNum()">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option>
</select>
<div id="allWrap1"></div>
<div id="allWrap2"></div>
<div id="allWrap3"></div>
<div id="allWrap4"></div>
<div id="allWrap5"></div>
<script src="script.js"></script>
JavaScript
var auth = '<select class="con'+ '' +'">' + '<option>Author</option>' + '<option>Editor</option>' + '<option>Compiler</option>' + '<option>Translator</option>' + '</select>' + '<br/>' + '<div class="authWrap">' + '<input id="author1F" class="infoMed" placeholder="First">' + '<input id="author1M" class="infoShort" placeholder="M.I.">' + '<input id="author1L" class="infoMed" placeholder="Last">' + '</div>' + '</div>'
function contNum() {
var contNum = document.getElementById("selectCon").value;
contNumGlobal = contNum;
var c;
for (c = 0; c < contNum; c++){
var tc = c.toString;
var tid = "allWrap" + tc;
document.getElementById(tid).innerHTML = auth;
}
}
The problem is not with the long variable as I have tried to just make the inner HTML a string and I still got the same error message. I also messed around with changing the 'tc' and 'tid' variable types (to string and float and num) but wasn't able to get it to work. If you could provide any feedback it would be very helpful, and thank you for taking your time to read this, it means a lot.