简体   繁体   English

在不提交表单的情况下获取表单文本字段的值

[英]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.

相关问题 无需提交表单即可获取输入字段的值 - Get value of input field without submitting form 动态获取隐藏字段值而无需提交表单 - dynamically get hidden field value without submitting form 如何在不提交表单的情况下按键盘上的回车键获取文本值 - How to get text value by pressing enter on keyboard without submitting the form 如何在不提交表单的情况下获取html中的option / text的值 - how to get value of option/text in html without submitting a form 如何在不提交表单的情况下获取javascript中输入字段的值? - How can I get the value of an input field in javascript without submitting a form? 从输入字段获取值并使用ajax传递到新页面,而无需提交表单 - Get value from input field and pass to new page using ajax without submitting form 从没有表单的文本字段输入中获取值 - Get value from text field input without form 使用Jquery Fancybox提交表单,然后将值附加到父级文本字段中 - Submitting form with Jquery Fancybox and then appending value into parents text field 在提交表单之前尝试访问 PHP 中文本字段的值 - Trying to access the value of a text field in PHP before submitting the form 如何在不提交表单的情况下从输入字段获取文件路径? - how to get file path from input field without submitting the form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM