I am working on a order form for sandwiches. The four input fields indicate the quantity of the product. (Brown, white bread etc.)
I am looking for suggestions on how to "live" display the products with quantity and price on the bottom of that page.. Also i want to calculate totals. AJAX looks the best way in my opinion; but where do i start?
At this moment the products are static inside html, is it wise to use xml for that? (mysql is not a option at the moment)
I hope this question makes some kind of sense, and will give me some possibilities.
Do you think so you get to have any idea?
A simple example ok? :)
Live: http://jsfiddle.net/WPxgF/
Html:
<table>
<tr>
<td>Product<td>
<td>Price<td>
<td>Qtd<td>
</tr>
<tr class="item">
<td>Sandwich<td>
<td class="price">3.00<td>
<td class="quant"><input type="text" size="4" value=""/><td>
</tr>
<tr class="item">
<td>Juice<td>
<td class="price">1.50<td>
<td class="quant"><input type="text" size="4" value=""/><td>
</tr>
<tr>
<td>Total<td>
<td><input type="text" size="4" id="amount" value=""/><td>
<td><input type="text" size="4" id="quant" value=""/><td>
</tr>
</table>
Javascript:
$(document).ready(function(){
$(".quant input").blur(function(){
var amount = 0;
var quant = 0;
$(".quant input").each(function() {
var thisQ = this.value;
quant += Number(thisQ);
var price = $(this).closest("tr").find(".price").html();
amount += calcTot(thisQ, price);
});
$("#quant").val(quant);
$("#amount").val(amount);
$(".price").each(function() {
price += Number($(this).html());
});
});
});
function calcTot(quant, price){
var tot = quant * price;
return tot;
}