Results 1 to 2 of 2

Thread: mailto: form with javascript

  1. #1
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mailto: form with javascript

    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

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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

    Code:
    <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>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •