peterS.: Mit Formularfeldern rechnen

Beitrag lesen

gruss Thomas,

schau Dir das mal an:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>_myCalculator.html</title>
<script language="JavaScript" type="text/javascript">
<!--
function updateResults()
 {var valueA = (document.forms["calculate"].elements["A"].checked ? 1 : 0);
  var valueB = (document.forms["calculate"].elements["B"].checked ? 1 : 0);
  var valueC = (document.forms["calculate"].elements["C"].checked ? 1 : 0);
  var valueD = (document.forms["calculate"].elements["D"].checked ? 1 : 0);
  document.forms["calculate"].elements["summe1"].value = valueA+valueB;
  document.forms["calculate"].elements["summe2"].value = valueC+valueD;
  document.forms["calculate"].elements["produkt"].value = (valueA+valueB)*(valueC+valueD);
  top.focus();
 }
//-->
</script>
</head>

<body onload="updateResults();">
<form name="calculate">
<table width="200">
    <tr>
      <td>
        <input type="checkbox" name="A" checked onclick="updateResults();">
      </td>
      <td>
        <input type="checkbox" name="B" checked onclick="updateResults();">
      </td>
      <td>
        <input type="text" name="summe1" onfocus="updateResults();" onblur="updateResults();">
      </td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" name="C" checked onclick="updateResults();">
      </td>
      <td>
        <input type="checkbox" name="D" checked onclick="updateResults();">
      </td>
      <td>
        <input type="text" name="summe2" onfocus="updateResults();" onblur="updateResults();">
      </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
      <td>
        <input type="text" name="produkt" onfocus="updateResults();" onblur="updateResults();">
      </td>
    </tr>
  </table>
 </form>
</body>

</html>

viel spass - by(t)e by(t)e - peterS. - pseliger@gmx.net