使用JS将表单值通过URL传递到另一个页面

时间:2018-04-13 08:08:19

标签: javascript jquery

我目前陷入这种状态。我想要做的是从表单输入名称和电子邮件,并将值重定向到另一个页面,但值应显示在下一页的地址栏中,关键是这应该只在JavaScript中完成。

以下是表单外观: enter image description here

值将显示如下: enter image description here  其中 xxxxx 名称电子邮件

表单的代码:

<form method="post" class="af-form-wrapper" accept-charset="UTF-8" action="https://www.aweber.com/scripts/addlead.pl"  target="_blank">
<input type="hidden" name="redirect" value="https://wanderistlife.typeform.com/to/gNucJF" id="redirect_984cda7485160f2afcf0ac36e7276fca" />
<input type="hidden" name="meta_redirect_onlist" value="https://wanderistlife.typeform.com/to/gNucJF"/>
<input type="hidden" name="meta_adtracking" value="My_Web_Form_2" />
<input type="hidden" name="meta_required" value="name (awf_first),name (awf_last),email" />

<label class="previewLabel" for="awf_field-96665553-first">First Name:</label>
<input id="awf_field-96665553-first" type="text" class="text" name="name (awf_first)" value=""  onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="500" />

<label class="previewLabel" for="awf_field-96665553-last">Last Name:</label>
<input id="awf_field-96665553-last" class="text" type="text" name="name (awf_last)" value=""  onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="501" />

<label class="previewLabel" for="awf_field-96665554">Email: </label>
<input class="text" id="awf_field-96665554" type="text" name="email" value="" tabindex="502" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " />

<input name="submit" onclick="HandleSubmit()" class="submit" type="submit" value="Submit" tabindex="503" />
<div class="af-element privacyPolicy" style="text-align: center"><p>We respect your <a title="Privacy Policy" href="https://www.aweber.com/permission.htm" target="_blank" rel="nofollow">email privacy</a></p>


 </form>

这就是我所做的:

   function HandleSubmit() {
    var baseUrl = "https://wanderistlife.typeform.com/to/gNucJF?";
    baseUrl += "name=" + document.getElementById("awf_field-96665553-first").value +"&email="+  document.getElementById("awf_field-96665554").value;


    window.location.href = baseUrl; 
     }

现在,当我在名称和电子邮件字段中输入值并点击提交按钮时,我将重定向到下一页。 下一页的地址栏: enter image description here

什么都没发生!

我想要的是,如果我在表单中输入name = navjot,那么URL栏将包含https://wanderistlife.typeform.com/to/gNucJF?name=navjot我知道这很简单,但我不知道如何在javascript中做任何帮助,感谢任何帮助或示例会帮助我。

0 个答案:

没有答案