We help IT Professionals succeed at work.

Microsoft JScript runtime error: Unable to set value of the property 'enabled': object is null or undefined

rcowen00
rcowen00 asked
on
I am trying to validate a text field dependent on if a checkbox is checked or not.  I have the checkbox set to checked and the validation runs as expected.  If I try to uncheck the checkbox so the validation is not run, I get the following error regarding the code.   I don't know even where to start with this, any suggestions?

Microsoft JScript runtime error: Unable to set value of the property 'enabled': object is null or undefined
function ValidatorEnable(val, enable) {
    val.enabled = (enable != false);
    ValidatorValidate(val);
    ValidatorUpdateIsValid();
}

Open in new window

Comment
Watch Question

GlobaLevelProgrammer

Commented:
How is the checkbox in the html with asp:checkbox or html? set it to a function

<asp:checkbox id="CheckBox1"></asp:checkbox>
<asp:button id ="button1" onclientclick="javascript:validator;false"></asp:button>
then in your js:

<script.....language..javascript>
var chc = document.getElementById("<%= CheckBox1.ClientID %>")
</script>


or this:
function CbValue() {
          alert($("#<%= CheckBox1.ClientID %>").is(':checked'));
       
         }

Author

Commented:
This is what I have now

<asp:CheckBox ID="ckBillingAddressDifferent" runat="server" 
                                    OnClick="ValidatorsEnabled(this.checked);" Checked="True"/>

Open in new window

Programmer
Commented:
whar r u doing in the JS..can you post?

Author

Commented:
Here you go
<script type="text/javascript" language="javascript">
       function InitValidators() {
           // retrieve instance of our checkbox
           var checkbox = document.getElementById('<%=ckBillingAddressDifferent%>');
           // enable/disable all validators on page based on checkbox state
           ValidatorsEnabled(checkbox.checked);
       }

       function ValidatorsEnabled(state) {
           ValidatorEnable(document.getElementById('<%=rfvMailingAddr%>'), state);
       }
    </script>

Open in new window