I just finished a quick project where the client wanted a HTML form that he could host locally on his PC. The form was to be filled out often, and upon submitting, the contents are  emailed to the desired representative in the field. Sound easy? Leaving a blank mailto won’t work.

To create a form like this start out by building your regular web page, and whatever form fields that you desire. To get the mailto action to work for various emails there is only one trick, and all it requires is some javascript.

Below is the javascript and HTML for the form fields you will need to edit:

<body>
<SCRIPT language=”JavaScript”>
function OnSubmitForm()
{
if(document.pressed == ‘Email‘)
{
var email = prompt(“Please enter the email the form will be submitted to:”);
var toemail = “mailto:’” + email + “‘”;
document.emailform.action = (toemail);
}
}
</SCRIPT>
<form name=”emailform” onSubmit=”return OnSubmitForm();” method=”post” enctype=”text/plain”>
<Misc Text Fields>
<input type=”submit” onClick=”document.pressed=this.value” VALUE=”Email” />
</body>

Starting with the form, the only thing unusual is the onSubmit attribute. It’s telling the form to complete the javascript function once the submit button has been clicked. Notice the submit button also has a little javascript.

If you are having a problem getting this to work, look how I color coded. You may just be missing or not identifying elements correctly.

  220 Responses to “Variable Email Form with Mailto”

  1. I’m a web developer and I fully agree with your post. Your java script provided good very easy and result oriented not containing any error. Good sharing with all..

  2. Interesting solution, a quick way to get the job done. Still needs a captcha if it’s not public

  3. He actually hosted it on his PC? I’m going to try this out, pretty cool, but I’m doubtful.

  4. I tested the mailto and it worked! Thanks. This will help save me time

  5. Your provided java script code are awesome really. It make my task easy. Now with few editing, I can make this program easy run. Nice sharing with all..

  6. I tried out the script and it works perfect. Thank you

  7. Usefull tips. I must try it. Thanks

  8. I think nothing left here on this nice script.Thanks for this nice collection.keep it continue.

  9. Your above mentioned code is really very good. Its really helpful for a newbie as well as a exp fellow. Its awesome script many thanks for sharing with all…

  10. Thanks a lot for this post and your inspiration) It all really helps;-)

  11. I was looking for script like this. Thank You!!

  12. Verify this question and describe what is the independent and dependent variable:Can CO2 levels affect plant growth?

  13. Than You for this script. I was looking for something like this.

  14. Your above provided script is really very helpful. You share here good java script coding.And save a lot of time of visitors..

  15. Thanks for this tip. It’s very usefull for me.

  16. Thanks for this information. I must test on my website.

  17. I would say I have wonderful blog n also good script for my blog.Thanks for sharing…

  18. Nice and simple for beginners. More bit of code like this thanks :)

  19. Thanks for this tip. I should use it on my website.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>