I am trying to pass an object through HTML but am getting the
Uncaught SyntaxError: Unexpected end of input
error. I am still learning JavaScript DOM and would appreciate any help.
data = getdata(); //retreive my data
var mtable = document.createElement("table"); //create table element via javascript
mtable.innerHTML += "<tr><th>Name</th><th>Modify</th></tr>";
for (i = 0; i < data.length; i++) {
var ins = createEle("tr");
ins.innerHTML = "<td>" + data[i]['name'] + "</td>";
ins.innerHTML += "<td><button id=" + data[i]['tid'] + " onclick=make_modifytourney2(this.id," + data[i] + ")>Modify</button></td></tr>";
mtable.appendChild(ins);
}
I am then appending mtable
to the document. data[i]
is an array object which I want to pass via this code but it is not working. I know that I can use tid
to retrieve again this data but I'd rather not since the data is already there.
Edit: My createEle
function createEle(ele, css) {
var nn = document.createElement(ele);
nn.setAttribute("class", css);
return nn;
}
a simple helper Edit 2 My array data will be something like this
data=[(4) [{…}, {…}, {…}, {…}]
0
:
{name: "T1", tid: 1, fdate: "2018-07-11", tdate: "2018-07-26", category: "mens", …}
1
:
{name: "T2", tid: 2, fdate: "2018-07-20", tdate: "2018-07-26", category: "womens", …}
2
:
{name: "nart", tid: 3, fdate: "0001-01-01", tdate: "0001-01-01", category: "1", …}
3
:
{name: "xyz", tid: 4, fdate: "0001-01-01", tdate: "0222-02-01", category: "23", …}]