Q:

Javascript form - different email based on choice

I am using a javascript form with a server-side processor and I want to be able to have the form go to different emails based on the dropdown. I've gotten as far as I could based on other forms but I can't seem to get the emails to go through.   I have added under the option tag on the email addresses for the choices and changed the value from an overall form email to "mailTo" () I am pretty sure this is where the issue is but I don't know how to fix it.

<form action="http://www.testsite.com/cgi-sys/formmail.pl" method="post" name="hgmailer">
<input type="hidden" name="recipient" value="mailTo">
<input type="hidden" name="subject" value="Website Consult Request">
<table width="100%" border="0" cellspacing="10px" cellpadding="10px">
  <tbody>
    <tr>
      <td>Nearest Location*</td>
      <td><select id="mailTo" name"mailTo">
       <option value="option1@testsite.com">Option1</option>
       <option value="option2@testsite.com">Option2</option>
       <option value="option3@testsite.com">Option3</option>
       <option value="option4@testsite.com">Option 4</option>

       </select></td>
</tr>
  </tbody>
</table><p>&nbsp;</p>
<input type="button" value="Schedule a Consultation" onclick="hgsubmit();" class="button">
<input type="hidden" name="redirect" value="thankyou.html">
</form>

A:

EDIT - My final code did not save previously
What you can do is add a javascript function to change the value of "recipient" to the selected email like...

function changeVal() {
var selectedVal = document.getElementById("mailTo").value;
document.getElementById("recipient").value = selectedVal;

var test = document.getElementById("recipient").value;
//alert(test);
  
}
<form action="http://www.testsite.com/cgi-sys/formmail.pl" method="post" name="hgmailer">
    <input type="hidden" name="recipient" id="recipient" value="mailTo">
    <input type="hidden" name="subject" value="Website Consult Request">
    <table width="100%" border="0" cellspacing="10px" cellpadding="10px">
      <tbody>
        <tr>
          <td>Nearest Location*</td>
          <td><select id="mailTo" name"mailTo" onchange="changeVal()">
           <option value="option1@testsite.com">Option1</option>
           <option value="option2@testsite.com">Option2</option>
           <option value="option3@testsite.com">Option3</option>
           <option value="option4@testsite.com">Option 4</option>
    
           </select></td>
    </tr>
      </tbody>
    </table><p>&nbsp;</p>
    <input type="button" value="Schedule a Consultation" onclick="hgsubmit();" class="button">
    <input type="hidden" name="redirect" value="thankyou.html">
    </form>

...I added an alert that you can comment out if you would like to test. Also I did this in javascript and not Jquery as you only asked for that.

