title: how to update the form field automatically
body: <p>I am developing a task management system in that i am having the age field in registration form i am having doubt about how to update the field automatically when i click.
  my script is</p>
  
  <pre><code>&lt;script&gt;
      var a = document.age1.dob.value;
      age = a.getFullYear();
      var curr = new Date();
      year = curr.getFullYear();
      var age1 = year - age;
  &lt;/script&gt;
  </code></pre>
  
  <p>i calculated the age and stored it in <code>age1</code> variable. </p>
  
  <pre><code>&lt;form id="form2" action="#" method="post" name="age1"&gt;
  &lt;h4&gt;&lt;b&gt;Register here&lt;/b&gt;&lt;/h4&gt;
  &lt;b&gt;Name&lt;/b&gt;: &lt;input type="text" name="name" required="required" placeholder="Your name" pattern="[a-zA-Z0-9\s]+"&gt;&lt;br&gt;&lt;br&gt;
  &lt;b&gt;E-mail&lt;/b&gt;: &lt;input type="email" name="email" required="required" placeholder="someone@example.com" pattern="[a-z0-9._+%-]+@[a-z0-9.-]+\.[a-z]{2,4}$"&gt;&lt;br&gt;&lt;br&gt;
  &lt;b&gt;Password&lt;/b&gt;: &lt;input type="password" name="password" required="required"&gt;&lt;br&gt;&lt;br&gt;
  &lt;b&gt;DOB&lt;/b&gt;: &lt;input type="text" name="dob" required placeholder="dd/mm/yyyy" pattern="^[0-3]?[0-9].[0-3]?[0-9].(?:[0-9]{2})?[0-9]{2}$"&gt;&lt;br&gt;&lt;br&gt;
  &lt;b&gt;Age&lt;/b&gt;: &lt;input type="text" name="age" id="age2"&gt;&lt;br&gt;&lt;br&gt;
  &lt;b&gt;Address&lt;/b&gt;: &lt;textarea name="address" rows="6" cols="30"&gt;&lt;/textarea&gt;
  &lt;button id="butr" type="submit" class="btn btn-warning"&gt;Signup&lt;/button&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/KtRED.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KtRED.png" alt="enter image description here"></a></p>
  
  <p>After i input my DOB in the registration form and click the age field i want the calculated age that i stored it in <code>age1</code> variable to automatically update the value in age field that i have it in my registration form</p>