Click here to Skip to main content
15,917,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 10-Jul-17 23:24pm
v3
Comments
Andy Lanng 11-Jul-17 4:33am    
What do you mean "next time"? take me through the process one step at a time
ZurdoDev 11-Jul-17 8:18am    
Just debug it. Simple.

1 solution

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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900