问题描述
我有一个用户输入值的输入文本字段( name:qtyText
)。我想使用JavaScript将此值设置为另一个隐藏字段( name:qtyTextHidden
)的值。
I have an input text field (name: qtyText
) to which a user enters a value. I would like to set this value as the value for another hidden field (name: qtyTextHidden
) using JavaScript. How can I go about it?
HTML
<input name = "qtyText" type = "textbox" size = "2" value = "" />
<input type="hidden" value = "" name="qtyTextHidden"/>
我努力使用JS工作设置字段值,但我无法将值发送给servlet的。所以我试图直接使用函数设置值,然后尝试将它发送到servlet。我想要一个 value = someJSFunction()
类。该函数需要在qtyText输入字段中的onChange上触发。
My efforts to set the field value using JS work, but I am unable to send the value to the servlet. So I am attempting to directly set the value using a function and then try and send it to the servlet. I would like to have a value = someJSFunction()
kind. The function needs to trigger upon "onChange" in the "qtyText" input field.
推荐答案
使用jQuery:
Using jQuery:
$(document).ready(function() {
$('input:text[name="qtyText"]').keyup(function() {
$('input:hidden[name="qtyTextHidden"]').val( $(this).val() );
});
});
使用JavaScript:
Using JavaScript:
window.onload = function() {
if(document.readyState == 'complete') {
document.getElementsByTagName('input')[0].onkeyup = function() {
document.getElementsByTagName('input')[1].value = this.value;
};
}
}:
这篇关于将Javascript输入隐藏字段的值设置为在另一个输入文本字段中输入的值的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!