Yannam
Yannam

Reputation: 21

Java script returning undefined when triggered

this is the function, and below designer code. I have updated the code with the latest answer

   function OnClientLoBChecked(sender, args) {

    var ChkBoxLOB = document.getElementById("<%= cbFLoB.ClientID %>");
    var ChkBoxDis = document.getElementById("<%= chkBoxShowNewProjects.ClientID %>");  
    if (ChkBoxLOB.Checked) {

        ChkBoxDis.checked = false}
    else{
        ChkBoxDis.checked = true

    }
    filterChanged();
    } 

    <telerik:radcombobox id="cbFLob" runat="server" datatextfield="LobName" checkboxes="true" OnClientItemChecked="OnClientItemChecked">

Upvotes: 0

Views: 94

Answers (1)

Dmitriy Khaykin
Dmitriy Khaykin

Reputation: 5258

Aside from the incorrectly capitalized document.getElementById() in your code, the real issue is that ChkBoxLob will always be undefined.

You are using $find which is an ASP.net function that finds components registered with the addComponent method.

These components are .net AJAX server controls that have a JavaScript counterpart. The $find() method is not meant to be used like the JavaScript document.getElementById() or the jQuery $('#someId) notation.

That is why chkBoxLob is always undefined;

Use document.getElementById instead in both places.

var ChkBoxLob = document.getElementById("<%= cbFLob.ClientID %>");
var ChkBoxDis = document.getElementById("<%= chBoxNewProjects.ClientID %>");

Note also the capitalized .ClientID property.

Upvotes: 2

Related Questions