-2

I am wanting to use a mailto form like the one below <form action="MAILTO:someone@example.com" method="post" enctype="text/plain"> Name:<br> <input type="text" name="name" value="your name"><br> E-mail:<br> <input type="text" name="mail" value="your email"><br> Comment:<br> <input type="text" name="comment" value="your comment" size="50"><br> <br> <input type="submit" value="Send"> <input type="reset" value="Reset"> </form>

but instead of it sending it to a predefined address i want the user to be able to choose the address. I also want the user to choose a subject using a simple text box for both. Any help is highly appreciated thanks

1 Answers1

0

You would need to use JavaScript to change the action attribute based on form inputs. If you put id='my_form' into <form> and have these fields:

Then a JavaScript function triggered by a button would do this

document.getElementById('my_form').setAttribute('action',
    'mailto:' + encodeURIComponent(document.getElementById('email_to').value) +
    '?subject=' + encodeURIComponent(document.getElementById('subject').value)
);
mike.k
  • 3,277
  • 1
  • 12
  • 18
  • The submit button needs to trigger the function which runs that code, and then submits the form, might be best to use ` – mike.k Jun 03 '15 at 20:58