[英]How to submit a form without putting an onload event in the body tag
我有幾個表單已同步到當前使用Avada主題在WordPress網站上運行的Salesforce,但客戶端需要添加一個新字段,這需要在body標簽中添加onload事件。 我認為最簡單的方法是通過儀表板>主題選項>高級>代碼字段,但我沒有看到添加事件到body標簽的選項。 如果不編輯核心模板文件(表單只在幾頁上),最好的方法是什么?
當前代碼片段:
<form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST"><input type=hidden name="oid" value="00DU0000000H99p">
<input type=hidden name="retURL" value="https://www.sablesys.com/thank-you/">
<input type="hidden" name="member_status" value="Sent"/>
<!-- Campaign id for Quote Campaign -->
<input type="hidden" name="Campaign_ID" value="7010B000001Eiz3QAC" />
<input type="hidden" id="lead_source" name="lead_source" value="Website">
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" required/><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" required/><br>
<label for="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" required/><br>
<label for="email">Email</label><input id="email" maxlength="80" name="email" size="20" type="text" required/><br>
<label for="city">City</label><input id="city" maxlength="40" name="city" size="20" type="text" required/><br>
Notes:<br><textarea id="00NU0000003mN8A" name="00NU0000003mN8A" rows="25" type="text" wrap="soft" style="width: 100%"></textarea><br>
<input type="submit" name="submit">
</form>
客戶端請求添加的新代碼:
表單的新字段:
<input type="hidden" id="URL" name="URL" value="" >
一個新的onload事件:
<body onload="document.getElementById('URL').value = document.location.href">
有沒有辦法在腳本中執行window.onload? 我承認我不懂javascript。 請在回復中說明。 謝謝。
這行代碼是javascript。
document.getElementById('URL').value = document.location.href;
你只需要一種方法來執行它。
如果您的頁面上正在執行任何其他JavaScript代碼,請將其作為其中的一部分。 您可以在表單中添加“onsubmit”事件,如下所示:
<form onsubmit="FillInURL()">
<input id="URL" type=hidden>
</form>
function FillInURL() {document.getElementById('URL').value = document.location.href;}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.