Solved

Mailto a TextBox value in Javascript/Html

Posted on 2004-08-03
10
4,314 Views
Last Modified: 2013-12-16
Hi,

First thanks for clicking

Have a Textbox called TeamString on a webpage.

Want to email the contexts of this Textbox in the mailto weblink

This is what I currently have

<a href="(mailto:entry@thefanleague.co.uk?subject=FanLeague Team String">
  Email Stuart</a>

Want the value of the Textbox to go directly in the Body of the email.

Realise ?body= goes into the anchor link. but not sure how to get the textbox value "document.Form1.TeamString.value" into the Body of the email.

Please note the TeamString Textbox is dynamically built by the user by a combination of different values in different comboboxes, so therefore each textbox is different for each user.

Many many thanks
Stuart
0
Comment
Question by:StuartK
10 Comments
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11703892
<a href="#" onclick='doit()'>  Email Stuart</a>

function doit()
{
  document.Form1.action = "mailto:entry@thefanleague.co.uk?subject=FanLeague Team String&&body=" + document.Form1.TeamString.value;
}

Problem is:  mailto: is unreliable.  It relies on the user having a mail program  and that program being set up 'properly'.  Many are not; mine, for example.

Vinny
0
 

Author Comment

by:StuartK
ID: 11704169
Hi Vinny,

Thank for replying.

Gave it a try.
Changed name of function to fit with application

It didn't work. But is definately going into function since I put an alert statement at the start.

function SendTeamString()
{
alert (document.frmEntry.TeamString.value);
document.frmEntry.action = "mailto:entry@thefanleague.co.uk?subject=FanLeague Team String&amp;&amp;body=" +
document.frmEntry.TeamString.value;
}

<a href="#" onclick='SendTeamString()'> Send Team</a>

Put this just above another function that I have, so guess I know it's in the right place.

Could it be the reliability issue you were talking about or am I missing something??

Your help is much appreciated Vinny,
Stuart


0
 
LVL 19

Expert Comment

by:webwoman
ID: 11704295
It's EXACTLY what Vinny was talking about.

Use another machine, a different browser (or different version), and it might work fine. You don't know, you can't know, and you also can't keep the user from changing the email or make the user mail it.

Process it on the SERVER, you know it works, and works for everybody. Plus spammers can't get your email from the mailto tag, because there isn't one. ;-)

You DO realize that's how they get a lot of emails, right?
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11704340
sorry :(

  I haven't had any espresso yet....

1)
this:    '&amp;&amp;'      should be:     '&&'

2)

function SendTeamString()
{
alert (document.frmEntry.TeamString.value);
window.location = "mailto:entry@thefanleague.co.uk?subject='FanLeague Team String'&&body=" + document.frmEntry.TeamString.value;
}

I wrote the function up as if it were for a form submission...again, sorry -- I'll go make some java now -- in case I messed up again :)
0
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 95 total points
ID: 11704433
Hi webwoman :D

Stuart,
 webwoman does have a point.  However, if your site doesn't have any serverside mail support, you can break up the addy [like below]. It won't stop human spammers, but you won't have to worry about spiders.

function SendTeamString()
{
alert (document.frmEntry.TeamString.value);
  var toTxt = 'entry';
  var domainTxt = 'thefanleague.co.uk';
  window.location = "mailto:" + toTxt + '@' + domainTxt + "?subject='FanLeague Team String'&&body=" + document.frmEntry.TeamString.value;
}

espresso almost done now :)
Vinny
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Assisted Solution

by:hyperslug
hyperslug earned 30 total points
ID: 11704448
Use VincentPuglia's code with window.open:

function SendTeamString()
{
      window.open = "mailto:entry@thefanleague.co.uk?subject=FanLeague Team String&amp;body=" + document.frmEntry.TeamString.value );
}

Also, use only 1 "&amp;".  It doesn't work with two like you have above.
0
 

Author Comment

by:StuartK
ID: 11704661
Thanks to all who helped and gave comments.

Vinny, can't thank you enough mate.

Only issue was as hyperslug suggested only needed 1 "&" - Thanks HyperSlug

Works perfect mate.

People on EE always astonish me how much they know and how helpful they are.

Hi Webwomen, point taken about ServersideScript but I don't have that support yet. Oh and yes, I am spammed 100's of times a day due to Website. Thanks for comfirming my worst suspicions.

Thank you to all.
0
 
LVL 11

Expert Comment

by:raj3060
ID: 11705505
Hi Stuart,
It was a bit tricky, anyway here is the working code,
++++++++++++++++++++++++++++++++
<html>
<head>
<title>Insert Text</title>
<script>
function mail(){
var message = document.form1.text1.value;
alert(message);
window.location="mailto:you@you.com?subject=Insert Text&body="+message+" ";
}
</script>
</head>
<body>
<form name="form1">
<textarea name="text1"></textarea>
<input type="button" onclick="javascript:mail()" value="MAIL" />
</form>
</body>
</html>
++++++++++++++++++++++++++++++++

I hope this is what you are looking for.
--Raj

0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11706319
Hi Stuart,

  You're welcome.  Sorry I tried answering your question with my eyes and mind still closed :D

Vinny
0
 

Author Comment

by:StuartK
ID: 11707763
Hi Raj,

God I'm really sorry mate, but Vinny gave me similiar code.

It's a perfect answer as well!! For people in the future looking for a similiar solution in the search engines, even though it's not the "Accepted Answer" it's just as good.

It's like I said previously, it astonishes me how helpful people are on EE.

I cannot thank you enough Raj. I hope you recognise my genuineness by showing the courtesy of replying to the post, mate.

My best wishes,
Stuart
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now