473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 18748
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom | last post by:
Anybody know how to modify this script to return to the HTML page from which it was launched? <script language="javascript"> document.location.href="MailTo:"; </script>
4
by: Ciar?n | last post by:
Hi all, I've go a little mailto: link on a page that when clicked opens an email form with the email address in the To field - all very simple. Problem is that in Netscape, a new blank window is...
13
by: Jeff Thies | last post by:
It's occured to me that most SPAM bots are looking for mailto links (that's assuming they didn't harvest from usenet!). So: <script type="text/javascript"> document.write('<a href="mailto:...
4
by: web_design | last post by:
I put this together from some other scripts I am using on a site. I'm trying to make a better email hiding script. It isn't working. Also, it causes Internet Explorer 6 SP2 to block the script...
4
by: Goo | last post by:
Hi. Looking for some advice. I have a simple javascript that gathers email from a HTML form and then upon the submit button click, it opens a default mail window with "mailto" and inserts...
11
by: mike_solomon | last post by:
Hi I have a link on a website that if you click opens up outlook <button onClick="location.href='mailto:a@b.com?subject=test subject'" > Select</button> Works fine But I want to include...
1
by: Larry Rebich | last post by:
I'm trying to launch the user's email client using 'MailTo:'. So I put a button on an aspx page and wrote some .vb code to use 'Mailto:' and it works on my development machine when I press the...
5
by: Joh | last post by:
I'm using mailto to open up an email that have a hyperlink in the body. The hyperlink passes two variables Name and Emailadress. The problem is that only the first variable Name show up in the...
3
by: moho | last post by:
Hi, I tried to do this: mailstr = "mailto:recipient@domain.com?subject=subjecextract&body=assg"; mailform = document.getElementById("mailform"); mailform.setAttribute('action',mailstr);...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.