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.

Easy and useful javascript, just need to copy and add the eamil address
Yes, that’s makes it a great solution for a quick contact
The the power of javascript can do… cool..
Not to mention jQuery
That’s the power of javascript… cool..
That sure is the power of a javascript coupled with great ingenuity.
Good JavaScript coding it is. One of the best blog post I read in recent past. This post have great content. I can stand up and say superb! There is sufficient reason why you got more visitors to your article.
Good post, thanks. I was actually wondering how to do this myself.. I always get my cousin to help me with it!
Nice thanks. Its always good to have options.
You are having a knack for simplicity !
Wonderful post, I really enjoyed reading it! The people you meet when you travel really are often the best part of it all!
Fully agree with your points here. All the posts are fully informative and having very good themes. I love to visit your blog again and again its really increase my knowledge. Thanks for the awesome post.
Great post
the 3DTV Reviewer Blog has more impact (for me) and it is still very readable.
Hi,
I’d like to offer a selection, from a drop down list of recipients, to whom the FORM should be emailed.
When using ‘mailto:’ – is it possible to use a variable to set this?
If so, can anyone suggest some code to demo this please?
I just tried to reply with a block of code, but it looks like it renders it as HTML and it won’t show up, I’ll try to create it on an external page and link you up.
thanks succesfull ? am like1
thanks succesfull ? am like2
thanks succesfull ? am like3
thanks succesfull ? am like4 thanks futurent
I will try this javascript code for my website. thanks for this code.
Very nice java script coding. I appreciate your knowledge.
Thanks for sharing…
This is a very useful script. Thank you for sharing
This is a great script thank you for sharing it us