Friday, 12 February 2016

Fix error - 0x800a138f - JavaScript runtime error: Unable to get property 'checked' of undefined or null reference

Watch this example on YouTube:



To fix the following error:
0x800a138f - JavaScript runtime error: Unable to get property 'checked' of undefined or null reference

Replace
    <form id="form1" runat="server">
        <div>
            <script language="javascript" type="text/javascript">
                function AdjustControls() {
                    var Month = document.getElementById('<%= rbMonth.ClientID %>');
                    var Range = document.getElementById('<%=rbRange.ClientID %>');
                    if (Month[0].checked) {
                        alert('month checked')
                    }
                    else {
                        alert('month not checked')
                    }
                }
            </script>

        </div>
        <div class="SearchLabels">
            <asp:RadioButton ID="rbMonth" runat="server" Text="Month" Checked="true"
                 GroupName="SearchBy" onclick="AdjustControls();" />
            <asp:RadioButton ID="rbRange" runat="server" Text="Range"
                 GroupName="SearchBy" onclick="AdjustControls();" />
        </div>
    </form>

with
    <form id="form1" runat="server">
        <div>
            <script language="javascript" type="text/javascript">
                function AdjustControls() {
                    var Month = document.getElementById('<%= rbMonth.ClientID %>');
                    var Range = document.getElementById('<%=rbRange.ClientID %>');
                    if (Month.checked) {
                        alert('month checked')
                    }
                    else {
                        alert('month not checked')
                    }
                }
            </script>

        </div>
        <div class="SearchLabels">
            <asp:RadioButton ID="rbMonth" runat="server" Text="Month" Checked="true"
                 GroupName="SearchBy" onclick="AdjustControls();" />
            <asp:RadioButton ID="rbRange" runat="server" Text="Range"
                 GroupName="SearchBy" onclick="AdjustControls();" />
        </div>
    </form>

No comments:

Post a Comment