简体   繁体   English

如何使用javascript将文本框的值传递给禁用的文本框

[英]How to pass the value of the text box to the disabled text box using javascript

I am having the text box where we will enter the value in the text box and while entering the value needs to be added to the disabled text box using javascript 我有一个文本框,我们将在文本框中输入值,输入时需要使用javascript将其添加到禁用的文本框中

Thanks, Vara Prasad.M 谢谢,Vara Prasad.M

If you want it to change the disabled input as you enter text , a server side solution is definitely not the right move because posting back in real time is not feasible. 如果您希望它在输入文本时更改禁用的输入,则服务器端解决方案绝对不是正确的选择,因为实时回发是不可行的。 Here's something client side using jQuery: 这是使用jQuery的客户端:

$("#abledtextbox").live({
    keyup: function(){
        $("#disabledtextbox").val($(this).val())
    }
});

can you use jQuery? 你可以使用jQuery吗?

$("#idOfSecondTextbox").blur( function() {
  $(#idOfSecondTextBox).val( $("#idOfFirstTextBox").val() );
});

Since you didn't ask for jQuery, here's a plain JavaScript solution: 由于您不要求使用jQuery,因此这里提供了一个简单的JavaScript解决方案:

function setValue(inputId, value)
{
    document.getElementById(inputId).value = value;
}

And the HTML: 和HTML:

<input id="text1"
    onkeyup="setValue('text2', this.value)"
    onchange="setValue('text2', this.value)" />
<input id="text2" />

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

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