是否可以使用其中一个字段动态更改html表单的操作标记值的值? [英] Is it possible to dynamically change the value of html form's action tag value with one of its fields?
问题描述
我搜索了很多(SO& GOOGLE)但是找不到更接近解决我问题的方法。
I searched a lot(S.O & GOOGLE) but was not able to find any closer looking approach to solve my problem.
我有一个简单的html5表单9-10输入并使用mailto:abc@xyz.com标签组成一封电子邮件,其中包含所有输入数据。
到此为止我很好,但现在我需要用一个输入字段更改abc@xyz.com值。
I have a simple html5 form having 9-10 inputs and uses "mailto:abc@xyz.com" tag to compose an email having all the entered data through inputs in there. Upto here i'm fine but now i need to change the "abc@xyz.com" value with one of its input field.
例如
<form method="post" action="now it should have what is value of 1." enctype="text/plain">
1. <input type="Email" name="ToEmail" id="ToEmail" value="" required placeholder="Target Email Address.."/>
2.
3.
.
.
<button type="submit">Submit</button></div>
</form>
我自己试了一下:
创建了一个javascript函数
函数actionValue()
What i tried myself:
created a javascript function
function actionValue()
{
var email = document.getElementById('ToEmail').value;
var action = "mailto:"+email+"?subject=Test"
return action;
}
并像这样调用此函数
<form method="post" action="javascript:actionValue();" enctype="text/plain">
我怀疑我的逻辑或我使用javascript的方式有问题。
任何帮助都将受到高度赞赏。
I suspect that there is something wrong with my logic or the way i'm using the javascript. Any help will highly be appreciated.
谢谢,
ps:我对js不太好..
Thanks, p.s : I'm not that good with js..
推荐答案
你应该可以做一些事情:
You should be able to do something along the lines of:
<form method="post" action="javascript:;" onSubmit="this.action='mailto:'+document.getElementById('ToEmail').value;" enctype...>
这篇关于是否可以使用其中一个字段动态更改html表单的操作标记值的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!