title: How to replace data in html form with JavaScript
body: <p>I have created an HTML form with three fields. Field A for input text, and fields B and C for number input.</p>
  
  <p>I created a function to calculate B i C, and to output data from A,B and C onto the page.</p>
  
  <p>How can I make it so that field A must be filled in, and fields B and C must be a positive value?</p>
  
  <p>HTML:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Tax calculator&lt;/title&gt;
      &lt;meta charset="UTF-8"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          Field A:&lt;input id="name" type="text"&gt;
          Field B:&lt;input id="tBas" type="value"&gt;
          Field C:&lt;input id="tRat" type="value"&gt;
          &lt;button id="calc"&gt;Calculate !&lt;/button&gt;
      &lt;/div&gt;
      &lt;strong&gt;
          &lt;div id="name"&gt; &lt;/div&gt;
          &lt;div id="income"&gt; &lt;/div&gt;
          &lt;div id="rate"&gt; &lt;/div&gt;
          &lt;div id="result"&gt; &lt;/div&gt;
      &lt;/strong&gt;
      &lt;script src="testCalculate.js"&gt;
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre class="lang-js prettyprint-override"><code>function calculate() {
      var name = document.getElementById('name').value;
      var base = parseFloat(document.getElementById('tBas').value);
      var rate = document.getElementById('tRat').value;
  
      var taxPayer = ("First and last name: ") + (name);
      var taxIncome = ("Income for taxation: ") + ((base).toFixed(2));
      var taxRate = ("Tax rate: ") + (rate) + ("%.");
      var taxToPay = ("You need to pay: ") + ((base * rate / 100).toFixed(2));
  
      document.getElementById('name').innerHTML = taxPayer;
      document.getElementById('income').innerHTML = taxIncome;
      document.getElementById('rate').innerHTML = taxRate;
      document.getElementById('result').innerHTML = taxToPay;
  }
  
  document.getElementById('calc').addEventListener('click', calculate);
  </code></pre>