Click to See Complete Forum and Search --> : Getting data from javascript into HTML
geuis
02-02-2003, 06:54 PM
Basically, what I am trying to do(and having a hard time doing it) is to have a normal
<a href="mailto:me@me.com?subject=Yo Momma">Click here</a>
Which works in bring up a pre-formatted email message.
What I need to do is to insert the time the email was created into the body of the message. I was envisioning somehow using javascript to generate the time, pass it to a variable, then pass that data to somehow insert it into the body= part of the mailto:
I am basically at a loss as to how to get the HTML <a href="mailto:"> to incorporate a javascript variable. Any help on this problem is MUCH appreciated.
(hopefully someone can help before I go bald. ERG!)
Geuis
khalidali63
02-02-2003, 07:13 PM
The code snippet below will actually stop the balding process..
:D
cheers
Khalid
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5"></meta>
<meta name="Author" content="Khalid Ali"></meta>
<title>MAILTO</title>
<script type="text/javascript">
function emailVariableValue(){
var frm = document.forms;
var subject = "This email is being sent using a function by variables"
var body = "This email was generated at ["+new Date()+"]";
frm[0].action = "MAILTO:k_ali@shaw.ca\?&subject\="+subject+"&body="+body+";";
return true;
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="comments" method="POST" onsubmit="return emailVariableValue();" enctype="application/x-www-form-urlencoded">
Thanks for taking some time to send me your views
<br><input type="Submit" value="Submit"> <input type="RESET"></p>
</form>
</body>
</html>
geuis
02-02-2003, 08:29 PM
that code works well for making an email that auto-sends, but what I need to have it do is simply make my email client(outlook 2002) open a new mail message w/ To:, Subject:, and Body: already populated with information, which is going to be generated from the javascript code variables. Is there anyway to modify the code you gave to work w/
<a href="mailto:anyone@any.com?subject=TestSub" + bodyvariable?
Thanks.
geuis
02-03-2003, 07:18 AM
refresh
khalidali63
02-03-2003, 08:01 AM
I am sorry,I think I lost you,
Whats the difference between the code I posted and the way you want it to work?
other then tthat you are showing it to work from an ancor tag and I did it in javascript function?
khalid
geuis
02-03-2003, 08:52 AM
The code you wrote works perfectly for what it does. However, the reason I am writing this project is for a work environment. Basically, from a central webpage our employess use, they will be needing to select from a pop-up list different subjects for the email that will be generated. I am not worried about that coding, I can easily write and integrate that.
Basically, once they select a subject from the pop-up menu, we need it to automatically open a new email window from OutlookXP(our default email client) and it will have the To: and Subject: fields filled automatically. The following code already does this:
<a href="mailto:any@anywhere.com?subject=Test Subject">Click to send</a>
Only problem with that code is that the subject is hard coded. We can get around that by having three different <a href> links, but that's messy.
Also, and this is the main point of my problem, is that no matter how the new email form is generated, we need to have the webform also generate some information such as a time/date stamp and some additional internal info and have it populate the Body of the new email window automatically.
Basically, I can't figure out how to:
1) get Javascript to do the same thing as <a href="mailto:"... in making the new window and
2) get Javascript to pass information from the web page to the new email window.
Hope this helps to further clarify my problem. I think you code can be modified to do what I am thinking, but I'm not sure how.
Thanks.
AdamGundry
02-03-2003, 09:03 AM
You can use location.replace with a mailto as the target, something like this:
<script type="text/javascript">
function emailVariableValue(){
var subject = "This email is being sent using a function by variables"
var body = "This email was generated at ["+new Date()+"]";
location.replace("MAILTO:k_ali@shaw.ca\?&subject\="+subject+"&body="+body+";");
return true;
}
</script>
Then call this code when the subject is selected from the popup.
Adam