I am a newbie in Jquery. First of all I would like to say that I have researched almost a day regarding this query. TRied numberous methods, but none that works. I am trying to code a billing module with HTML, PHP and Jquery. Until now, I have successfully created the HTML tables. I would like the data from these tables to the retrieved to a PHP page, so that I can print them with a proper formatting.
The HTML Table is as follows.
<table id="items">
<tbody>
<tr>
<th>SlNo</th>
<th>Item</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr class="item-row">
<td class="item-name">
<div class="delete-wpr">
<input type="text" class="slno"/>
<a class="delete" href="javascript:;" title="Remove row">X</a>
</div>
</td>
<td><input type="text" class="slno"/></td>
<td><input type="text" class="cost"/></td>
<td><input type="text" class="qty"/></td>
<td><span class="price"></span></td>
</tr>
<input type="button" value="submit" onClick="storeAndShowTableValues()"/>
<tbody>
Now, the Jquery is as follows.
var TableData = new Array();
$('#items tr').each(function(row, tr){
TableData[row]={
"ItemNum" : $(tr).find('td:eq(0)').text(),
"Itemname" :$(tr).find('td:eq(1)').text(),
"unitprice" : $(tr).find('td:eq(2)').text(),
"Qty" : $(tr).find('td:eq(3)').text(),
"price" : $(tr).find('td:eq(4)').text()
}
}
);
TableData.shift(); // first row is the table header - so remove
var TableData = JSON.stringify(TableData);
But the JSON object I am getting is garbage. The table data is not retrieved. Please help.