my shoppingcart is working but i used to many var and functions and i think it looks sloppy. i dont know how to set it right.
here is the Jsfiddle link:
https://jsfiddle.net/z0c1ja37/
can someone help me to put things right in this code?
look at my jsfiddle link there is the full code
$('.productprijzen').hide();
var $select = $('<select>').addClass('keuzes');
$select.append('<option>Kies je optie</option>');
$select.append('<option value="volvo">Volvo</option>');
$select.append('<option value="saab">saab</option>');
$select.append('<option value="peugeot">peugeot</option>');
$select.append('<option value="mazda">mazda</option>');
$select.on('change', function () {
$parent = $(this).closest(".row");
$('.productprijzen', $parent).slideDown();
// prijs en btw laten zien
var merk = $(this).val();
var productInfo = oProducten[merk];
$parent.find('.prijs').html("€" + productInfo.prijs);
$parent.find('.btw').html(productInfo.btw + "%");
// berekening van aantal x prijs
var $aantalKeuze = $parent.find('input.aantal');
var $subtotaal = $parent.find('.sub');
$aantalKeuze.bind('keyup mouseup', function () {
var $subtotaalUiteindelijk = productInfo.prijs * $aantalKeuze.val();
$subtotaal.html($subtotaalUiteindelijk);
var totaalBtw6 = 0;
var totaalBtw21 = 0;
var $totaal = 0;
var $subtotaalVeld = $(".sub");
$subtotaalVeld.each(function () {
if ($(this).text() !== "") {
$totaal = $totaal + Number($(this).text());
}
});
});
to end the block started with$select.on('change', function () {
. This may also be whytotaalBtw6
andtotaalBtw21
are never used. \$\endgroup\$