So I'm attempting to add all textboxes that are dynamically generated to get a subtotal.
here is my code that generates the boxes:
<table id="billing-table">
<tr>
<th>Service</th><th>Price</th><th>Subtotal</th>
</tr>
<?PHP
$aService = $_POST['service'];
$N = count($aService);
for($i=0; $i < $N; $i++)
{
$services=MYSQLI_QUERY($con, "SELECT * FROM `Service` WHERE Service_ID = '$aService[$i]'")or die(mysqli_error($con));
$getservices = mysqli_fetch_array($services);
$serviceid = $getservices['Service_ID'];
$servicedesc = $getservices['Service_Type'];
$serviceprice = $getservices['Service_Cost'];
echo'<tr>
<td><input type="text" name="service" value="'. $servicedesc. '"></td>
<td><input type="text" name="price" id="price'.$i.'" value="'. $serviceprice. '"></td>
<td><input type="text" class="qty" value="'. $serviceprice. '"></td>
</tr>';
} ?>
<tr>
<td style="position:absolute;left:5%;">Subtotal</td>
<td></td>
<td><input type="text" id="total" value=""></td>
</tr>
</table>
I'm attempting to use jquery to do this based off of this fiddle: http://jsfiddle.net/LJKjR/478/
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$('input.qty').change(function() {
// Loop through all input's and re-calculate the total
var total = 0;
$('input.qty').each(function(){
total += parseInt(this.value);
});
// Update the total
$('#total').val(total);
});
</script>
</head>
I have everything in place with no errors, but no total value of all prices combined in my subtotal textbox? what am i doing wrong?