I have this HTML structure in one of my pages:
<table width="300">
<tr>
<td width="65">Travelers</td>
<span id="traveller-count"></span>
<td>Total</td>
</tr>
</table>
I am trying to populate the #traveller-count
<span>
with dynamic data, using javascript. However, the (javascript) generated <td>
tags fail to show up in the rendered page. As a result, the data shows up outside of the table, rather than inside the table.
Any ideas on how I can resolve this issue will be really appreciated.
Below is my javascript code:
var passengers = { '1':{'age':'ad'}, '2':{'age':'ad'}, '3':{'age':'ch'}, '4':{'age':'in'} }
var ts = '';
var adultCount = childCount = infantCount = 0;
for(var x in passengers)
{
currPassenger = passengers[x];
ts += '<td width="52">';
ts += '<span style="color:#fff;">';
switch(currPassenger.age.toUpperCase())
{
case 'AD' : ts += 'Adult-' + ++adultCount; break;
case 'CH' : ts += 'Child-' + ++childCount; break;
case 'IN' : ts += 'Infant-' + ++infantCount; break;
}
ts += '</span>';
ts += '</td>';
}
document.getElementById("traveller-count").innerHTML = ts;