I'm currently writing a little (html&javascript-)application in a .hta file, but somehow document.getElementById seems to return nothing (undefined) while executed in the .hta application, but when pasted in jsfiddle, the code works fine.
<!DOCTYPE html>
<html>
<head>
<script>
...
(function (){loadDataFromFile();})();
function loadDataFromFile(){
...
try {
...
for(var i = 0; i < tmpReqs.length; i++){
...
addHTMLReq(i);
}
}catch(Err){
alert("File content contains errors.\n"+Err.message);
}
}
function addHTMLReq(reqID){
var req = reqs[reqID];
if(!req) return;
var contentElement = document.getElementById("main_table");
alert(contentElement.innerHTML); //To debug, already fails here.
var tr = document.createElement("tr");
tr.id = req.id;
var td_0 = document.createElement("td");
td_0.id = "date";
td_0.innerHTML = req.day + "/" + req.month + "/" + req.year;
tr.appendChild(td_0);
var td_1 = document.createElement("td");
td_1.id = "source";
td_1.innerHTML = reqSources[req.source];
tr.appendChild(td_1);
var td_2 = document.createElement("td");
td_2.id = "requirement";
td_2.innerHTML = req.requirement;
tr.appendChild(td_2);
contentElement.appendChild(tr);
}
</script>
</head>
<body>
<div id="category_definition">
<category id="cat0" name="My Category 1" topCat="none" />
</div>
<div id="content">
<div id="categories">
</div>
<table id="main_table">
<tr>
<th id="date">Date</th>
<th id="source">Source</th>
<th id="requirement">Description</th>
</tr>
<tr id="100">
<td id="date">28/01/2015</td>
<td id="source">src</td>
<td id="requirement">Lorem Ipsum dolores est</td>
</tr>
</table>
</div>
</body>
</html>
I omitted the useless part of the code. All variables used ARE properly defined, the only problem lies in the document.getElementById, createElement, etc methods.
Does anyone know what the problem could be?