Wednesday, 29 January 2014

Javascript - how to fix error - JavaScript runtime error: Object doesn't support property or method 'setAttribute'


Watch online

Replace

    <script type="text/javascript">
        function CheckTextBox() {
           var AccountNumber = document.getElementById('<%= txtSomething.ClientID %>').value;
            if (document.getElementById('<%= rbCheckYesNo.ClientID %>').checked) {
                AccountNumber.setAttribute("readonly", "false");
                AccountNumber.focus();
            }
        }
    </script>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="txtSomething" onchange="CheckTextBox()" runat="server"></asp:textbox>
        <asp:radiobutton id="rbCheckYesNo" runat="server">
    </asp:radiobutton></div>
</form>
</body>
with

    <script type="text/javascript">
        function CheckTextBox() {
           var AccountNumber = document.getElementById('<%= txtSomething.ClientID %>');
            if (document.getElementById('<%= rbCheckYesNo.ClientID %>').checked) {
                AccountNumber.setAttribute("readonly", "false");
                AccountNumber.focus();
            }
        }
    </script>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="txtSomething" onchange="CheckTextBox()" runat="server"></asp:textbox>
        <asp:radiobutton id="rbCheckYesNo" runat="server">
    </asp:radiobutton></div>
</form>
</body>

1 comment:

  1. You can fix this error by ensuring that the object HostMyCode you're trying to use setAttribute on is a valid DOM element:

    ReplyDelete