469,336 Members | 5,570 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Javascript and mailto


I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.

I can create a mailto link in the page using innerHTML, but it seems
silly to click a button, a link appears, then click on the link.

How do I execute the mailto command using JavaScript?

And before I get beaten up over using mailto, it's for a simple
intranet application to get the answers to a couple of survey
questions. I know all my users have one of two browsers and the same,
fully configured e-mail client. The alternative is for some MS script
guru to code the thing as a Word macro...yechh

Some play code follows.

Regards, Rob.

<html><head><title>Mail to page</title>
<script type="text/javascript">
function sendValues(f,x) {
var a = f.elements;
var b = "The message:";
for (var i=0; i<a.length; i++) {
if (a[i].parentNode.nodeName == 'LABEL'){
if (a[i].type =='textarea' || a[i].type =='text')
b += writeB(a[i]);
if (a[i].type =='radio' && a[i].checked)
b += writeB(a[i]);
}
}
alert(b)
alert(escape(b));
document.getElementById(x).innerHTML = '<a href=\''
+ 'mailto:ro*@myemail.com?SUBJECT=E-mail from a form'
+ '&body=' + escape(b) + '\'>Click here to send...</a>';
}
function writeB(x){
return '\n' + x.name + ': ' + x.value;
}
</script>
<style type="text/css">
body {font-family: sans-serif; margin-left: 40;}
input {font-family: sans-serif;}
label {padding-bottom: 40;}
</style>
</head>
<body margin>
<form action="">
<label for="a1">Enter text 1<br>
<input type="text" name="a1"><br>
<label for="a2">Enter text 2<br>
<textarea name="a2" rows="5" cols="30"
wrap="physical"></textarea><br>
<label for="a3">Pick an option
<input type="radio" name="a3" value="none" checked="checked"
style="display: none;"><br>
<input type="radio" name="a3" value="A">Option A<br>
<input type="radio" name="a3" value="B">Option B<br>
<input type="radio" name="a3" value="C">Option C<br>
</label><br>
<input type="reset" value="Clear all entries">&nbsp;
<input type="button" value="Click to submit" onclick="
sendValues(this.form,'xx');
">
</form>
<div id="xx"></div>
</body>
</html>
Jul 23 '05 #1
5 18466
RobG wrote:

I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.


As a quick note, Lotus Note seems to only allow a body of 200
characters when using mailto - so keep your survey short!

Fred.
Jul 23 '05 #2
In article <TA****************@news.optus.net.au>, RobG says...

I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.


mailto: as a form action doesn't work. Use a server-side process. Read
the links here:
http://www.allmyfaqs.com/faq.pl?Email_form_data

--
Hywel

http://sponsorhywel.org.uk/
Jul 23 '05 #3
Hywel wrote:
In article <TA****************@news.optus.net.au>, RobG says...
I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.

mailto: as a form action doesn't work.


I'm not trying to use it as a form action - see my play code.

However, can you explain why the following works? I haven't tested it
in IE with XP SP2, but it works in IE, Firefox, Safari...

<form action="mailto:yo*@yourdmainhere.com"
method="post" enctype="text/plain">
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
<input type="submit" name="submit" value="Submit">
</form>

Use a server-side process. Read
I've said I don't want to do that. This is for an intranet where the
system admin nazis won't even let me see the security settings of IE:
they are not going to let me setup a web server or use one of theirs.

Perhaps I should have said a HTML page on a file server rather than a
web page.
the links here:
http://www.allmyfaqs.com/faq.pl?Email_form_data


Great, but my play code does more than those links will teach you.
Now, if I wanted to setup a server... :-)

I want to do this for a very limited environment, it is not for the web
or use beyond a team of about 20 people.

Cheers, Rob.
Jul 23 '05 #4
In article <TA****************@news.optus.net.au>, rg***@iinet.net.auau
enlightened us with...

I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.

I can create a mailto link in the page using innerHTML, but it seems
silly to click a button, a link appears, then click on the link.

How do I execute the mailto command using JavaScript?


You don't.
You've overcomplicating things.

If you want the form fields to get mailed from a link click, just use mailto
as the action of the form (like you did in your other post). Then, instead of
a submit button, do
<a href="javascript:document.formname.submit();">Clic k to submit</a>

The form fields will all get mailed. No other javascript required.

Note that this is only for intranet apps, which you said yours was. There's a
crapload wrong with it for internet use. :)

--
--
~kaeli~
Frisbeetarianism (n.), The belief that, when you die, your
soul goes up on the roof and gets stuck there.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5
In article <417e0489$0$13758$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, RobG says...
Hywel wrote:
In article <TA****************@news.optus.net.au>, RobG says...
I am trying to get users to fill in a form on a web page, then click a
button to send an e-mail. I am using JavaScript to get the fields from
the form, then run a mailto command to put the information into an
email.

mailto: as a form action doesn't work.


I'm not trying to use it as a form action - see my play code.

However, can you explain why the following works? I haven't tested it
in IE with XP SP2, but it works in IE, Firefox, Safari...

<form action="mailto:yo*@yourdmainhere.com"


It doesn't. It works *for you*.
Use a server-side process. Read


I've said I don't want to do that. This is for an intranet where the
system admin nazis won't even let me see the security settings of IE:
they are not going to let me setup a web server or use one of theirs.


Perhaps they'll also disable this functionality, too. Buy them cookies
in return for them installing Apache. I'd be surprised if they haven't
got a machine running IIS you could access. Offer them photos of things
they won't normally see, such as trees or their wives/girlfriends
nekkid.

--
Hywel

http://sponsorhywel.org.uk/
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Jeff Thies | last post: by
4 posts views Thread by web_design | last post: by
11 posts views Thread by mike_solomon | last post: by
5 posts views Thread by Joh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.