I have a table:
<div ID="documents_list" style="visibility: hidden;">
<table style="background-color:#000000;border:0;border-collapse:separate;border-spacing:0px;">
<tr>
<td style="padding:0px;">
<table id="documentsTable" style="border:0;border-collapse:separate;border-spacing:1px;">
<tr bgcolor='#ffffff'>
<td bgcolor='#cccccc' style="padding:2px;" nowrap>Catalog:</td>
<td style="padding:2px;" colspan=3></td>
</tr>
<tr bgcolor='#ffffff'>
<td bgcolor='#cccccc' style="padding:2px;" nowrap>Doc.nr.</td>
<td bgcolor='#cccccc' style="padding:2px;" nowrap>Document name</td>
<td bgcolor='#cccccc' style="padding:2px;" nowrap></td>
<td bgcolor='#cccccc' style="padding:2px;" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<input type="button" value="Close" onClick="hide_documents_list()">
</div>
And I'm trying to access it from Javascript, so I could change it's content and add rows to it. The method for it is following:
function show_documents(documents) {
var table = document.getElementById("documentsTable");
for (var i=0; i<documents.length; i++) {
var row = table.insertRow(-1);
var document = row.insertCell(0);
var name = row.insertCell(1);
var button = row.insertCell(2);
var checkbox = row.insertCell(3);
document.innerHTML = documents[i].document;
name.innerHTML = "<a href='${pageContext.request.contextPath}/s?id=" + documents[i].document + "'>" + documents[i].name + "</a>";
button.innerHTML = "<input type='button' value='Delete'>";
name.innerHTML = "<input type='checkbox'>";
}
show_documents_list();
}
But whenever I try to call this method, I get the following error Uncaught TypeError: Cannot read property 'getElementById' of undefined. The thing is, the element is defined in HTML, so I can't really figure out where the problem is.