I'm fetching data from a PHP file with jQuery and I want it to be displayed dynamically in a table. Is there another way of doing this, so that the jQuery itself creates the table rows? This is my attempt..
Part from the html file:
<table id="tejbl">
<tr id="naslov">
<td><h3>NAME</h3></td>
<td><h3>FAT</h3></td>
<td><h3>FIBER</h3></td>
<td><h3>SUGARS</h3></td>
</tr>
<tr>
<td id="table_0"></td>
<td id="table_1"></td>
<td id="table_2"></td>
<td id="table_3"></td>
</tr>
</table>
Part from the js file:
$('#jedinice_butt').click(function(){
var odabrano = $("#dropdown option:selected").text();
var uneseno = $("#input_jedinica").val();
$('#tablica').show();
//$('#add_button').show();
if(odabrano === "g"){
$.post('name.php', {
value: value
}, function (data) {
$('#table_0').html(data);
});
$.post('nutritional_value.php', {
value: value
}, function (data) {
$('#table_1').append( data * (parseFloat(uneseno,10)/100));
});
$.post('fiber.php', {
value: value
}, function (data) {
$('#table_2').append(data * (parseFloat(uneseno,10)/100) );
});
$.post('sugars.php', {
value: value
}, function (data) {
$('#table_3').append( data * (parseFloat(uneseno,10)/100) );
});
}
The problem I'm trying to solve is, that once I click the button again it just adds the values in the same 's and I want it to add in a new row.. So basically how do you dynamically add rows for these outputs I tried with a few methods with no success I event tried doing it without the 's in the html file so it's generated from the jQuery but I'm doing something wrong apparently.