Javascript and mailto

R

RobG

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.parentNode.nodeName == 'LABEL'){
if (a.type =='textarea' || a.type =='text')
b += writeB(a);
if (a.type =='radio' && a.checked)
b += writeB(a);
}
}
alert(b)
alert(escape(b));
document.getElementById(x).innerHTML = '<a href=\''
+ 'mailto:[email protected]?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>
 
F

Fred Oz

RobG said:
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.
 
R

RobG

Hywel said:
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:[email protected]"
method="post" enctype="text/plain">
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
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.

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.
 
K

kaeli

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();">Click 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
 
H

Hywel

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:[email protected]"

It doesn't. It works *for you*.


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top