当我从javascript分配文本框时,如何获得文本框的价值? [英] How to get value of textbox when I am assigning it from javascript?

查看:68
本文介绍了当我从javascript分配文本框时,如何获得文本框的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我选中了一个复选框,当我选中其他文本框的值应该被分配给该文本框并被禁用时,但是当我取消选中它时,用户应输入自己的值。



一旦我检查并插入相同的值,它就会保存到该值,但下次更新文本框时我无法读取新值。



我的Javascript函数是这样的。



I have one checkbox when i check that checkbox the value of other text box should be assigned to that text box and it get disabled ,but when i unchecked it user should input his own value.

Once i check and insert the same values it get saved to that value, but next time when i update the text boxes i am not able to read new values.

My Javascript function is like this.

function SetValues(ObjId) {

           if (document.getElementById(ObjId).checked) {
                document.getElementById('<%= txtBillAddr1.ClientID %>').value =
                    document.getElementById('<%= txtadress.ClientID %>').value;
                document.getElementById('<%= txtBillAddr2.ClientID %>').value =
                    document.getElementById('<%= txtAddr2.ClientID %>').value;
                document.getElementById('<%= txtBillCity.ClientID %>').value =
                    document.getElementById('<%= txtCity.ClientID %>').value;
                document.getElementById('<%= txtBillState.ClientID %>').value =
                    document.getElementById('<%= txtState.ClientID %>').value;
                document.getElementById('<%= ddlBillCountry.ClientID %>').value =
                    document.getElementById('<%= ddlcountry.ClientID %>').value;
                document.getElementById('<%= txtBillZipCode.ClientID %>').value =
                    document.getElementById('<%= txtZIP.ClientID %>').value;
                document.getElementById('<%= txtBillContctperson.ClientID %>').value =
                    document.getElementById('<%= txtcontactperson.ClientID %>').value;
                document.getElementById('<%= txtBillPhNo.ClientID %>').value =
                    document.getElementById('<%= txtPhone.ClientID %>').value;
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
                document.getElementById('').setAttribute("readonly", "readonly");
                document.getElementById('').setAttribute("style", "background-color:#DCDCDC");
            }
            else {
               
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");
                document.getElementById('').removeAttribute("readonly");
                document.getElementById('').setAttribute("style", "background-color:#FFFFFF");

            }
        }





我的尝试:



我为我的文本框存在的那个块添加了更新面板。

仍然没有按要求工作。



What I have tried:

I added update panel for that block where my text boxes exists.
Still not working as required.

推荐答案

您可以尝试添加和删除下面的属性,让我知道这是否可以解决您的问题?



设置只读属性 -

document.getElementById('')。attr(readonly,true);



删除它 -

document.getElementById('')。attr(readonly,false);
Can you try adding and removing attribute like below instead and let me know if this resolves your problem?

To set readonly attribute -
document.getElementById('').attr("readonly", true);

To remove it -
document.getElementById('').attr("readonly", false);


这篇关于当我从javascript分配文本框时,如何获得文本框的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆