DCJones
DCJones

Reputation: 3451

DataTables and Bootstrap 3 Uncaught SyntaxError: Invalid or unexpected token

I have a script that generates a dynamic table using dataTables and Bootstrap 3 Modal. The table contain x number of row depending on the result of an Ajax call. The last column needs to be a drop-down list which the user can select and option prior to saving.

The issue I have is the code is returning an error:

Uncaught SyntaxError: Invalid or unexpected token

This is on line marked X. Where am I going wrong?

var tr_str = "<tr class='TableText'>" +
    "<td style='color:#333;font-size:0.8em;white-space: nowrap;'>" + promotionimage + "</td>" +
    "<td style='color:#333;width:12px;height:12px'><input type='image' src='../img/view_image.png'   id=' + recordid + ' class='img-responsive center-block btn-block view_data_image'></td>" +
    "<td align='center' style='color:#333;font-size:0.8em;'>" + Day0 + '' + Day1 + '' + Day2 + '' + Day3 + '' + Day4 + '' + Day5 + '' + Day6 +"</td>" +
    "<td align='center' style='color:#333;font-size:0.8em;'>" + displayorder + "</td>" +
    // LINE X
    "<td align='center' style='color:#333;font-size:0.8em;'>
    <select name='ViewOrder' id='ViewOrder' class='timetext' required >
        <option value='1'>1</option>
        <option value='2'>2</option>
        <option value='3'>3</option>
        <option value='4'>4</option>
        <option value='5'>5</option>
        <option value='6'>6</option>
        <option value='7'>7</option>
        <option value='8'>8</option>
        <option value='9'>9</option>
        <option value='10'>10</option>
    </select>
    </td>" +
    // END LINE X
"</tr>";
$("#orderTable tbody").append(tr_str);

Upvotes: 0

Views: 1009

Answers (1)

anurag
anurag

Reputation: 2246

Any Javascript string if it goes to next line should be terminated by a \.

In your case

var tr_str = "<td align='center' style='color:#333;font-size:0.8em;'> \
    <select name='ViewOrder' id='ViewOrder' class='timetext' required > \
        <option value='1'>1</option> \
        <option value='2'>2</option> \
        <option value='3'>3</option> \
    </select>\
    </td>";

Upvotes: 1

Related Questions