I am trying to pass on an xml element variable to a JS function and I end up with Uncaught SyntaxError: Unexpected identifier
on client-side when pressing the button. The error goes away when I pass other simple variable like integer to the function. Does that mean that it is impossible to pass an XML object to a function?
Here's the code.
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp);
}
};
xmlhttp.open("GET", "/static/egais_files/ReplyRests.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th></th><th>Alco-code</th></tr>";
var x = xmlDoc.getElementsByTagName("StockPosition");
for (i = 0; i <x.length; i++) {
table += "<tr>" +
"<td>" + x[i].getElementsByTagName("AlcCode")[0].childNodes[0].nodeValue + "</td>" +
"<td><button onclick = 'populate_ttn1_xml(" + x[i] + ")' type='button' class='btn btn-primary'>OK</button></td>" +
"</tr>";
}
document.getElementById("egaisResultTable").innerHTML = table;
};
var populate_ttn1_xml = function(x)
{
result = 1
}
EDIT: Some more code added. The problem arises when pressing the OK button (function populate_ttn1_xml