简体   繁体   English

网址自动填充到页面上的框中

[英]Web address autofill into a box on the page

How can I make the web address of the page the user is currently on autofill into a box on the page?如何将用户当前所在页面的网址自动填充到页面上的框中?

On my websites 404 page we have a form for the user to fill out with name, email, etc. I would like one of the form boxes to autopopulate with the page the user is currently on.在我的网站 404 页面上,我们有一个表单供用户填写姓名、电子邮件等。我希望其中一个表单框可以自动填充用户当前所在的页面。

Here is the code I currently have:这是我目前拥有的代码:

 <form id="contactForm" class="scaffold-form" action="https://mpex.com/contacts/index/post/" method="post"> <div class="fieldset"> <h2 class="legend">Contact Information</h2> <p class="required">* Required Fields</p> <ul class="form-list"> <li class="fields"> <div class="field"><label class="required" for="name"><em>*</em>Name</label> <div class="input-box"><input id="name" class="input-text required-entry" title="Name" type="text" value="" name="name" /></div> </div> <div class="field"><label class="required" for="email"><em>*</em>Email</label> <div class="input-box"><input id="email" class="input-text required-entry validate-email" spellcheck="false" title="Email" type="email" value="" name="email" /></div> </div> </li> <li><label for="telephone">Telephone</label> <div class="input-box"><input id="telephone" class="input-text" title="Telephone" type="tel" value="" name="telephone" /></div> </li> <li class="wide"><label class="required" for="comment"><em>*</em>Comment</label> <div class="input-box"><textarea id="comment" class="required-entry input-text" title="Comment" name="comment" rows="3" cols="5"></textarea></div> </li> </ul> </div> <div class="buttons-set"><input id="hideit" style="display: none !important;" type="text" value="" name="hideit" /> <button class="button" title="Submit" type="submit"><span><span>Submit</span></span></button></div> </form>

 <form id="contactForm" class="scaffold-form" action="https://mpex.com/contacts/index/post/" method="post"> <div class="fieldset"> <h2 class="legend">Contact Information</h2> <p class="required">* Required Fields</p> <ul class="form-list"> <li class="fields"> <div class="field"><label class="required" for="name"><em>*</em>Name</label> <div class="input-box"><input id="name" class="input-text required-entry" title="Name" type="text" value="" name="name" /></div> </div> <div class="field"><label class="required" for="email"><em>*</em>Email</label> <div class="input-box"><input id="email" class="input-text required-entry validate-email" spellcheck="false" title="Email" type="email" value="" name="email" /></div> </div> </li> <li><label for="telephone">Telephone</label> <div class="input-box"><input id="telephone" class="input-text" title="Telephone" type="tel" value="" name="telephone" /></div> </li> <li class="wide"><label class="required" for="comment"><em>*</em>Comment</label> <div class="input-box"><textarea id="comment" class="required-entry input-text" title="Comment" name="comment" rows="3" cols="5"></textarea></div> </li> </ul> </div> <div class="buttons-set"><input id="hideit" style="display: none !important;" type="text" value="" name="hideit" /> <button class="button" title="Submit" type="submit"><span><span>Submit</span></span></button></div> </form> <script type="text/javascript"> window.onload = function () { document.getElementById('name').value = location.href; } </script>

You can add script after form tag like this您可以像这样在表单标签后添加脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM