title: Auto Complete email address field when name is selected
body: <p>Hi all I'm using this code for a datalist tag dropdown field to select a name and email from a list or allows for new name or email to be inserted (thanks Tanaike) that works great.
  I was wondering if someone could help me with the code to auto populate the email field if the selected name exist. The name list is from my Google sheet DD column 'B' and the email are in column 'C'
  here's the code I'm using. The way it workimg now I'm able to select the email but I would like it to auto populate.
  Thanks</p>
  <pre><code>&lt;!--------------- Name Select -------------------&gt;
        &lt;script&gt;
                      function namedd() {
                      var value = document.getElementById(&quot;input&quot;).value;
                      console.log(value)
                      }
                    &lt;/script&gt;
  
                    &lt;div class=&quot;form-row&quot;&gt;
                      &lt;div class=&quot;form-group col-md-5&quot;&gt;
                        &lt;label for=&quot;name&quot;&gt;name&lt;/label&gt;
                        &lt;input type=&quot;text&quot; id=&quot;input&quot; class=&quot;form-control&quot; list=&quot;name&quot; name=&quot;name&quot; placeholder=&quot;Select name&quot; &gt;
                        &lt;datalist id=&quot;name&quot;  &gt;
                       &lt;?
                        var sheet   = SpreadsheetApp.getActive().getSheetByName(&quot;DD&quot;);
                        var lastRow = sheet.getLastRow();
                        var myRange = sheet.getRange(&quot;B2:B&quot;+lastRow);
                        var data    = myRange.getValues();
                        for (var i = 0; i &lt; data.length; ++i) { ?&gt;
                        &lt;option value=&quot;&lt;?!= data[i] ?&gt;&quot;&gt;
                      &lt;? } ?&gt;
                      &lt;/datalist&gt;
                    
                      &lt;/div&gt;
  
  
  
  &lt;!--------------- Email Select -------------------&gt;
  
                   &lt;script&gt;
                      function emaildd() {
                      var value = document.getElementById(&quot;input&quot;).value;
                      console.log(value)
                      }
                    &lt;/script&gt;
  
                    &lt;div class=&quot;form-row&quot;&gt;
                      &lt;div class=&quot;form-group col-md-5&quot;&gt;
                        &lt;label for=&quot;email&quot;&gt;email&lt;/label&gt;
                        &lt;input type=&quot;email&quot; id=&quot;input&quot; class=&quot;form-control&quot; list=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Select email&quot; &gt;
                        &lt;datalist id=&quot;email&quot;  &gt;
                       &lt;?
                        var sheet   = SpreadsheetApp.getActive().getSheetByName(&quot;DD&quot;);
                        var lastRow = sheet.getLastRow();
                        var myRange = sheet.getRange(&quot;C2:C&quot;+lastRow);
                        var data    = myRange.getValues();
                        for (var i = 0; i &lt; data.length; ++i) { ?&gt;
                        &lt;option value=&quot;&lt;?!= data[i] ?&gt;&quot;&gt;
                      &lt;? } ?&gt;
                      &lt;/datalist&gt;
                    
                      &lt;/div&gt;
  
  
         
  </code></pre>