PDA

View Full Version : mailto: form with javascript



LifeIsBeta
11-21-2006, 02:41 PM
Hey all,

I'm needing to get javascript to pass the inputs from an html form to a mailto: statement.

I can't use server-side scripting, as this form will be locally hosted on our network.

Is this something that's pretty easy to do?

Thanks

codeexploiter
11-22-2006, 04:14 AM
Think you are looking for a JavaScript where variables can be a part of of a mailto link. Refer the following code.

There is one Javascript function (createAnchor) through which I construct the link



<html>
<head>
<script type="text/javascript">
function createAnchor(emailId,subject,body)
{
var mailTo;

mailTo = "mailto:";

if(!emailId)
{
alert('No mail ID passed; Quitting from the function');
return;
}

if(subject == '' && body == '')
{
document.write ("<A href='"+mailTo + emailId+"'>mail</A><br>");
}
else if(subject != '' && body == '')
{
document.write ("<A href='"+mailTo + emailId+"?subject="+subject+"'>mail</A><br>");
}
else if(subject == '' && body != '')
{
document.write ("<A href='"+mailTo + emailId+"?&body="+body+"'>mail</A><br>");
}
else if(subject != '' && body != '')
{
document.write ("<A href='"+mailTo + emailId+"?subject="+subject+"&body="+body+"'>mail</A><br>");
}

return;

}
</script>
</head>
<body>
These are test content, developed for the sole purpose of testing.<br>
if you want to contact the support please
<script type="text/javascript">
createAnchor("emailid@emailid.com","This is my subject","This is my body"); //function call
</script>
</body>
</html>