title: Javascript form automatic calculation
body: <p>I am trying to create form which automatically alters a text box when the user uses keystrokes .</p>
  
  <p>This fiddle illustrates what I am attempting however I have had no success.</p>
  
  <p>Essentially I want the 3rd text box to show the "Number of People" multiplied by the "Price", how can I do this?</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;form action="postenquiry.php" method="post" name="myform"&gt;
      &lt;label&gt;Num of People&lt;/label&gt;
      &lt;input type="text" name="qty" /&gt;
      &lt;br/&gt;
      &lt;label&gt;Price&lt;/label&gt;
      &lt;input type="text" name="Cost" onkeyup="calculate()" /&gt;
      &lt;br/&gt;
      &lt;input type="text" name="textbox5" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>function calculate() {
      if (isNaN(document.forms["myform"]["qty"].value) || document.forms["myform"]["qty"].value == "") {
          var text1 = 0;
      } else {
          var text1 = parseInt(document.forms["myform"]["qty"].value);
      }
      if (isNaN(document.forms["myform"]["Cost"].value) || document.forms["myform"]["Cost"].value == "") {
          var text2 = 0;
      } else {
          var text2 = parseFloat(document.forms["myform"]["Cost"].value);
      }
      document.forms["myform"]["textbox5"].value = (text1 * text2);
  }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/b87s5hou/" rel="nofollow">http://jsfiddle.net/b87s5hou/</a></p>