1

Temat: getElementById + - * /

<script>
  function f1()
  {
    var a = document.getElementById("a");
    var b = document.getElementById("b");
    var c = document.getElementById("c");
    var s = document.getElementById("s");
    //
    var x=0;
    if (s.value == 1)
      x = parseInt(a.value)+parseInt(b.value);
    if (s.value == 2)
      x = parseInt(a.value)-parseInt(b.value);
    if (s.value == 3)
      x = parseInt(a.value)*parseInt(b.value);
    if (s.value == 4)
      x = parseInt(a.value)/parseInt(b.value);
    c.value = x.toFixed(2);
  }
</script>
<form>
<input type="text" id="a">
  <select id="s">
    <option value="1">+</option>>
    <option value="2">-</option>>
    <option value="3">*</option>>
    <option value="4">/</option>>
  </select>
<input type="text" id="b">=
<input type="text" id="c">
<input type="button" value="Suma" onclick="f1()">
</form>
<hr>