JohnSmith JohnSmith - 1 year ago 65
HTML Question

How do I output the contents of an array in an html table while using jQuery?

How do I display the contents of an array in a HTML table while using jQuery?

Here's my script... This outputs the objects in the array on top of the table not in the table.


<th>ITEM ID</th>
<div id="returnlist"></div>


var tempList = new Array();
var split = $('#onhanditem').val().split('_');
var itemid = split['0'];
var kilo = $('#kilo').val();
var bagsReturned = $('#bagsReturned').val();
var totalbagkiloreturned = kilo+'_'+bagsReturned;
tempList[itemid] = totalbagkiloreturned;
list = '';
// i = ITEM ID | tempList = totalbagkiloreturned
for (var i in tempList){
var itemID = i;
var split = tempList[i].split('_');
var kilo = split['0'];
var numBags = split['1'];

Answer Source

As far as I'm aware, the middle of a table isn't a valid location for a <div> tag, which is why it's not being displayed inside the table. Why not put your id on the <tbody> tag instead, and do away with the div altogether?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download