[英]Javascript Redirect Based on a Form Selection (Before Submitting)
我希望根據用戶在 Hubspot 表單字段中做出的選擇將用戶重定向到不同的頁面(對於學術帳戶)。 理想情況下,這會在更改時發生,並在選擇它時立即發生,而不是在表單提交時發生。
ID: license_type_of_interest-cb1da23a-da50-42f8-b281-b8845c18b0a6
價值:學術許可
嘗試通過 Id 獲取它,將值與“Academic License”匹配,如果這是立即重定向到新的 url 的值。 另外,不幸的是使用 Wordpress 和 Hubspot forms。
Select 片段:
<select id="license_type_of_interest-cb1da23a-da50-42f8-b281-b8845c18b0a6" required="" class="hs-input" name="license_type_of_interest"> <option disabled="" value="">Please Select</option> <option value="Silver License">Silver</option> <option value="Gold License">Gold</option> <option value="Enterprise License">Enterprise</option> <option value="Academic License">Academic</option> <option value="Researcher License">Researcher</option> </select>
也許
const licences = {
"Silver License" : "silver.html",
"Gold License": "gold.html",
...
"Researcher License": "researcher.html"
};
document.querySelector("[id^='license_type_of_interest']") // a select with ID starting with 'license_type_of_interest'
.addEventListener("change", function() { // when changed
const val = this.value;
if (val) location = licenses[val]; // redirect to URL in object
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.