1

Temat: [JS] Lista zakupów (checkbox + getElementById)

<script>
  function klik()
  {
    var check1 = document.getElementById("check1").checked;
    var check2 = document.getElementById("check2").checked;
    var check3 = document.getElementById("check3").checked;
    var check4 = document.getElementById("check4").checked;
    var vat = document.getElementById("vat").checked;
    //
    p=0;
    if (check1) p+=4;
    if (check2) p+=3;
    if (check3) p+=9;
    if (check4) p+=12;
    if (vat) p=p+(p*0.23);
    //
    alert("do zaplaty: "+p+" zl");
  }
</script>
<form name="form1">
  <font size="+2">
  Lista zakupow:<br>
  <input id="check1" type="checkbox"> pieczywo<br>
  <input id="check2" type="checkbox"> nabial<br>
  <input id="check3" type="checkbox"> mieso<br>
  <input id="check4" type="checkbox"> ryby<br>
  <br><br>
  <input id="vat" type="checkbox"> z VAT 23%<br>
  </font>
  <br><input type="button" value="Sprawdz" onclick="klik()">
</form>