title: Javascript autocomplete Form and append text in prefilled feild
body: <p>I am trying to create a form that will auto complete text fields based on entered first name and last name.  For example:</p>
  
  <p>If the Lastname is : smith
  If the Firstname is: John
  The email address should be automatically completed as : smithj@abc.com
  And the Username should be automatically completed as: smithj.
  I have the follow code that completes the username but I can’t figure out how to complete the email part.  </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>&lt;form method="post" name="form" action=""&gt;
  &lt;div&gt;&lt;label for="lname"&gt;Last Name: &lt;/label&gt;&lt;input type="text" name="lname" id="lname" /&gt;&lt;/div&gt;
  
  &lt;div&gt;&lt;label for="fname"&gt;First Name: &lt;/label&gt;&lt;input type="text" name="fname" id="fname" onblur="
  if(document.form.username.value=='' &amp;&amp; document.form.lname.value!='' &amp;&amp; document.form.lname.value!='') {
       var username = '';
       if(document.form.fname.value.length &gt;= 4) {
            username = document.form.lname.value.substr(0,49) + document.form.fname.value.substr(0,1);
       } else {
            username = document.form.lname.value.substr(0,49) + document.form.fname.value.substr(0,4);
       }
       username = username.replace(/\s+/g, '');
       username = username.replace(/\'+/g, '');
       username = username.replace(/-+/g, '');
       username = username.toLowerCase();
       document.form.username.value = username; 
  
       }" /&gt;&lt;/div&gt;
  
  
  &lt;div&gt;&lt;label for="Email"&gt; Email:      &lt;/label&gt;&lt;input type="text" name="Email" /&gt;&lt;/div&gt;
  &lt;div&gt;&lt;label for="username"&gt;Username: &lt;/label&gt;&lt;input type="text" name="username" id="username"/&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>