Question

i want to dynamically create a table some of them having links to some other url with a loop, note: inside each i am filling dynamic html which has dynamic values that are filled from an array.My code is given bellow . When i run this code js returns an array "unexpected tocken 'for'" , I tried it with while also ..The error is same again. Help me out freaks..

html += '<tr class="' + (i % 2 == 0 ? 'grid_color' : '') + '" data-type="record"  data-record-id="' + records[i].id + '" data-row-index="' + i + '">'

+ '<td data-table-col="16" title="' + Samples.htmlEntities(records[i].name_id) + '">' +
for (i = 0; i < nameSplit.length; i++) {
    if (nameSplit[i] != "None") {
        name = nameSplit[i].split(".");
        name = name.shift();
        '<a target = "_blank" href="http://www.google.com/' + name + '">' + name.substr(0, 10 / nameSplit.length) + (name.length > 10 / nameSplit.length ? '...' : '') + '</a>'
    } else {
        if (i != nameSplit.length - 1) {
            "|";
        }
    } else {
        if (i != nameSplit.length - 1) "None".concat("|");
        else "None";
    }
}
}
'</td>'
Was it helpful?

Solution

I tried fixing your code indentation and format but it was just unreadable for me. But anyway, I'll do it as an example you adapt it to your specific needs.

var html = "<table>";
for(var i = 0; i<someCondition; i++){
  html +="<tr><td>Cell 1</td><td>Cell 2</td><tr>";
}
html += "</table>";

the error you are getting is because somewhere in your code you have something like ... + for(...) and that doesn't work, a for loop doesn't return so it won't get anything from it.

OTHER TIPS

You cannot do it that way. If your'e adding strings together, strings are expected. If you write code at that point, it's seen as in invalid string, rather than code that will generate the actual string.

You need to put all of the script before the part where you append strings to 'html'.
If you wrote this directly into the html source code (which is a horrible approach to it), you should read about the basics of applying scripts (I guess you're more experienced than that, though).

So: put script before the "html + A + B + ...".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top