Subtotalen berekenen werkt niet!
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<table id="items">
<tr>
<th>Aantal</th>
<th>Prijs</th>
<th>Subtotaal</th>
<th>BTW %</th>
<th>BTW</th>
<th>Totaal incl.</th>
</tr>
<tbody>
<tr class="targetfields">
<td><input type="text" name="quantity" id="quantity" class="quantity" /></td>
<td><input type="text" name="rate" id="rate" class="rate" size="5" /></td>
<td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly="readonly"/></td>
<td><input type="text" name="btw" id="btw" class="btw" size="5" /></td>
<td><input type="text" name="subbtw" id="subbtw" class="subbtw" readonly="readonly"/></td>
<td><input type="text" name="totaal" id="totaal" class="totaal" readonly="readonly"/></td>
</tr>
<tr class="targetfields">
<td><input type="text" name="quantity" id="quantity" class="quantity" /></td>
<td><input type="text" name="rate" id="rate" class="rate" size="5" /></td>
<td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly="readonly"/></td>
<td><input type="text" name="btw" id="btw" class="btw" size="5" /></td>
<td><input type="text" name="subbtw" id="subbtw" class="subbtw" readonly="readonly"/></td>
<td><input type="text" name="totaal" id="totaal" class="totaal" readonly="readonly"/></td>
</tr>
<tr class="targetfields">
<td><input type="text" name="quantity" id="quantity" class="quantity" /></td>
<td><input type="text" name="rate" id="rate" class="rate" size="5" /></td>
<td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly="readonly"/></td>
<td><input type="text" name="btw" id="btw" class="btw" size="5" /></td>
<td><input type="text" name="subbtw" id="subbtw" class="subbtw" readonly="readonly"/></td>
<td><input type="text" name="totaal" id="totaal" class="totaal" readonly="readonly"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td><input type="text" id="total"></td>
<td></td>
<td><input type="text" id="tbtw"></td>
<td><input type="text" id="ttot"></td>
</tr>
</tfoot>
</table>
<script>
$(function() {
$("#items").keyup(function(event) {
var total = 0;
$("#items .targetfields").each(function() {
var qty = parseInt($(this).find("#quantity").val());
var rate = parseInt($(this).find("#rate").val());
var btw = parseInt($(this).find("#btw").val());
var subtotal = qty * rate;
var subbtw = (qty * rate) / 100 * btw;
var totaal = ((qty * rate) / 100 * btw) + (qty * rate);
$(this).find("#subtotal").val(subtotal.toFixed(2));
$(this).find("#subbtw").val(subbtw.toFixed(2));
$(this).find("#totaal").val(totaal.toFixed(2));
if(!isNaN(subtotal))
total+=subtotal;
});
$("#total").val(total.toFixed(2));
$("#tbtw").val(tbtw.toFixed(2));
$("#ttot").val(ttot.toFixed(2));
});
})
</script>
<tr>
<th>Aantal</th>
<th>Prijs</th>
<th>Subtotaal</th>
<th>BTW %</th>
<th>BTW</th>
<th>Totaal incl.</th>
</tr>
<tbody>
<tr class="targetfields">
<td><input type="text" name="quantity" id="quantity" class="quantity" /></td>
<td><input type="text" name="rate" id="rate" class="rate" size="5" /></td>
<td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly="readonly"/></td>
<td><input type="text" name="btw" id="btw" class="btw" size="5" /></td>
<td><input type="text" name="subbtw" id="subbtw" class="subbtw" readonly="readonly"/></td>
<td><input type="text" name="totaal" id="totaal" class="totaal" readonly="readonly"/></td>
</tr>
<tr class="targetfields">
<td><input type="text" name="quantity" id="quantity" class="quantity" /></td>
<td><input type="text" name="rate" id="rate" class="rate" size="5" /></td>
<td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly="readonly"/></td>
<td><input type="text" name="btw" id="btw" class="btw" size="5" /></td>
<td><input type="text" name="subbtw" id="subbtw" class="subbtw" readonly="readonly"/></td>
<td><input type="text" name="totaal" id="totaal" class="totaal" readonly="readonly"/></td>
</tr>
<tr class="targetfields">
<td><input type="text" name="quantity" id="quantity" class="quantity" /></td>
<td><input type="text" name="rate" id="rate" class="rate" size="5" /></td>
<td><input type="text" name="subtotal" id="subtotal" class="subtotal" readonly="readonly"/></td>
<td><input type="text" name="btw" id="btw" class="btw" size="5" /></td>
<td><input type="text" name="subbtw" id="subbtw" class="subbtw" readonly="readonly"/></td>
<td><input type="text" name="totaal" id="totaal" class="totaal" readonly="readonly"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td><input type="text" id="total"></td>
<td></td>
<td><input type="text" id="tbtw"></td>
<td><input type="text" id="ttot"></td>
</tr>
</tfoot>
</table>
<script>
$(function() {
$("#items").keyup(function(event) {
var total = 0;
$("#items .targetfields").each(function() {
var qty = parseInt($(this).find("#quantity").val());
var rate = parseInt($(this).find("#rate").val());
var btw = parseInt($(this).find("#btw").val());
var subtotal = qty * rate;
var subbtw = (qty * rate) / 100 * btw;
var totaal = ((qty * rate) / 100 * btw) + (qty * rate);
$(this).find("#subtotal").val(subtotal.toFixed(2));
$(this).find("#subbtw").val(subbtw.toFixed(2));
$(this).find("#totaal").val(totaal.toFixed(2));
if(!isNaN(subtotal))
total+=subtotal;
});
$("#total").val(total.toFixed(2));
$("#tbtw").val(tbtw.toFixed(2));
$("#ttot").val(ttot.toFixed(2));
});
})
</script>
Een id moet uniek zijn en mag niet meerdere keren gebruikt worden.