是否可以动态设置MAILTO的收件人:只使用HTML和JavaScript?

时间:2011-07-29 01:13:29

标签: javascript html dynamic mailto

我正在创建一个仅使用HTML和JavaScript的表单,我希望能够通过更改MAILTO:地址或mailto:行的CC地址来动态设置POST表单的收件人。如果可能的话,这将由文本框的值确定。此功能的目的是根据表单数据在下拉菜单中的选择,将表单数据发送给不同的管理器。我已经在一个地方看到过这个(http://javascript.internet.com/forms/multiple-mailer.html),但我的问题是我从JS数组填充我的下拉列表,当选择时填充一些文本字段就像(http://www.webdeveloper.com/forum/showpost.php?p=984036&postcount=8)。所以我想要做的是用我的下拉填充隐藏的文本输入并从中绘制以确定谁收到电子邮件。

我应该注意,这是针对公司的INTRAnet网站,其中缺少桌面电子邮件客户端不是问题,并且IE是唯一可用的浏览器。我无法访问服务器端技术,所以mailto是我唯一的选择,请不要浪费评论告诉我它是多么糟糕,哈哈。谢谢!

思想?

3 个答案:

答案 0 :(得分:4)

使用某个电子邮件地址打开邮件客户端:

location = 'mailto:' + email_address;

要设置href元素的a,请先使用document.getElementById之类的内容进行设置,然后设置href属性:

document.getElementById('someLink').href = 'mailto:' + email_address;

email_address是一个包含适用电子邮件地址的字符串 - 您可以将其替换为获取下拉列表值的表达式:

document.getElementById('someLink').href = 'mailto:' + document.getElementById('dropdown').value;

答案 1 :(得分:0)

您可以使用Javascript将href属性设置为包含电子邮件地址的字符串。

答案 2 :(得分:0)

是的,有可能。我的表单中有一个与此类似的选项框:

<td><select name="Division" id="Division" onChange="dirChange()" tabindex="3">
<option selected>Choose One</option>
<option value="Communications">Communications</option>
<option value="Legal Services">Legal Services</option>
</select>        &nbsp;</td>

它指的是一个javascript函数:

function dirChange()
{
var i = document.all.Division.value;
switch (i)
{

    case "Communications":
        document.all.DeputyDirector.value = "Dave C.";
        document.all.form.action = "mailto:Dave.C@xxxxx.com?subject=Form";
        break;

    case "Legal Services":
        document.all.DeputyDirector.value = "Dixie P.";
        document.all.form.action = "mailto:Dixie.P@xxxxxx.com?subject=Form";
        break;

    default:
        document.all.DeputyDirector.value = "";
        break;

}
}

此javascript有助于在文本框中填写所需信息,并将表单发送给选定的人员。

<tr>
  <td class="announcementText"> <span class="style12"><span class="style16"><span class="style31">*</span></span></span>Division Deputy Dir.:  </td>
  <td><input name="DeputyDirector" type="text" id="DeputyDirector" style="background-color:#cccccc; color:black; font-weight:bold; border:0; overflow:visible" size="38"></td>

</tr>

<form onChange="dirChange()" method="post" enctype="text/plain" name="form" id="form"   onSubmit="return checkform(this);">

客户端选择通信部门后得到的html为: 对于文本框:

<input name="DeputyDirector" type="text" id="DeputyDirector" style="background-color:#cccccc; color:black; font-weight:bold; border:0; overflow:visible" size="38" value = "Dave C.">

以及表格:

<form onChange="dirChange()" method="post" enctype="text/plain" name="form" id="form"   onSubmit="return checkform(this); action = "mailto:Dave.C@xxxxx.com?subject=Form">

或者如果他们选择法律服务 对于文本框:

<input name="DeputyDirector" type="text" id="DeputyDirector" style="background-color:#cccccc; color:black; font-weight:bold; border:0; overflow:visible" size="38" value = "Dixie P.">

以及表格:

<form onChange="dirChange()" method="post" enctype="text/plain" name="form" id="form"   onSubmit="return checkform(this); action = "mailto:Dixie.P@xxxxxx.com?subject=Form">