[英]Get value of form text field with without submitting the form
I have a form on my page and want to be able to submit the text box value (partnumber) as a query string in a hyperlink without submitting the form itself ? 我的页面上有一个表单,希望能够在超链接中提交文本框值(partnumber)作为查询字符串,而无需提交表单本身? Is this possible ?
这可能吗 ? I have done some research and have tried document.getElementById("partnumber").value but am getting the error "Object Required".
我已经做了一些研究,并尝试了document.getElementById(“partnumber”)。value但是得到了错误“Object Required”。 Code Below.
代码如下。
<form id="form3" name="form3" method="post" action="formpost?rmaid=<%=rmaid%>">
<input name="partnumber" type="text" id="partnumber" size="10" />
<a href="suggest.asp?partnumber=<%document.getElementById("partnumber").value%>"><span class="style11">Suggest Link</span></a>
<input name="invoice" type="text" id="invoice" size="15" />
</form>
I'll set the new page to open in a pop up window and list a series of values in the database but then I need the value selected to come back into the invoice field on the original page. 我将新页面设置为在弹出窗口中打开并在数据库中列出一系列值,但我需要选择的值返回原始页面上的发票字段。 I believe this can be done with JavaScript but I am new to this, can anyone help ?
我相信这可以通过JavaScript完成,但我是新手,有人可以帮忙吗?
For those Looking to pass values back I have found this snippet that works... Put this in the child window 对于那些想要传递值的人,我发现这个片段有效...将它放在子窗口中
<script language="javascript">
function changeParent() {
window.opener.document.getElementById('Invoice').value="Value changed..";
window.close();
}
</script>
<form>
<input type=button onclick="javascript:changeParent()" value="Change opener's textbox's value..">
</form>
For the input field you should add an OnChange to it. 对于输入字段,您应该向其添加OnChange。 This event should call a function which will then set your link's value.
此事件应调用一个函数,然后设置链接的值。
You can see an example of this here (it uses a button press though and not an input OnChange Event): http://www.java2s.com/Code/JavaScript/HTML/ChangeURLandtextofahyperlink.htm 你可以在这里看到一个例子(虽然它使用按钮而不是输入OnChange事件): http : //www.java2s.com/Code/JavaScript/HTML/ChangeURLandtextofahyperlink.htm
Edit: Added a Stack Snippet illustrating the solution. 编辑:添加了一个说明解决方案的Stack Snippet。
function SetSuggestLink() { var suggest = document.getElementById('partnumber').value; document.getElementById('innerSpan').innerHTML = "Suggest Link: suggest.asp?partnumber=" + suggest; document.getElementById('QueryLink').href = "suggest.asp?partnumber=" + suggest; }
.style11 { color:black; } .style2 { text-decoration:none; }
<form id="form3" name="form3" method="post" action="formpost?rmaid=SomeValue"> <input name="partnumber" type="text" id="partnumber" size="10" OnChange="SetSuggestLink()" /> </br> <a id="QueryLink" class="style2" href="#"> <span id="innerSpan" class="style11">Suggest Link</span> </a></br> <input name="invoice" type="text" id="invoice" size="15" /> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.