This is a migrated thread and some comments may be shown as answers.

Javascript getElementByID returns null

2 Answers 921 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
nav100
Top achievements
Rank 1
nav100 asked on 28 May 2012, 03:45 AM

I am trying to find the control and display set to "block" or "none" on onclientselectedindexchanged event of RadCombobox. It returns always null. The script and controls are in User Control of Content page. There is also Master page for this Content page. I  debugged the code with Debugger statement but the control has this tag. "ctl00_content2_ucControl1_imgTest". How can show and hide image? Please let me know. Thanks for your help. Also I tried to use document.getElementById("<%=imgTest.ClientID"); and $find(("<%=imgTest.ClientID") ; but none of these working.

<asp:Image ID="imgTest" ImageUrl="../../../images/test.gif" AlternateText="test"
                            runat="server" style="display:none"></asp:Image>

<telerik:RadComboBox ID="Combobox1" runat="server" DataTextField="test1"
                            DataValueField="test_id" NoWrap="true" Width="250" onclientselectedindexchanged="OnClientSelectedIndexChanged">                        </telerik:RadComboBox>

 
<script type="text/javascript">

  

function OnClientSelectedIndexChanged(sender, eventArgs) {

     {
      var
item = eventArgs.get_item();

          if(item.get_value() == "8")

             {
            var imageControl = document.getElementById('imgTest');
            imageControl.style.display = "block"; 
            }
        }
</script>

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 May 2012, 06:35 AM
Hi,

Try accessing the image as shown below.
JS:
function OnClientSelectedIndexChanged(sender, args)
{
  var imageControl = document.getElementById('<%=imgTest.ClientID%>');
}

Thanks,
Shinu.
0
vaishali
Top achievements
Rank 1
answered on 18 Mar 2016, 11:46 AM

I am doing project on capture image and video in telerik.where getElementByIdb returning null value. donot know why this is happening.can any one suggest me changes to run project.

html:

   <div class="content">
            <div class="action-area ch50">
                <button type="submit" class="button dh" id="captureVideo1">Capture Video</button>
                <button type="submit" class="button dh" id="captureAudio1">Capture Audio</button>
                <button type="submit" class="button dh" id="captureImage1">Capture Image</button>
            </div>

main.js:

  var x=getBrowser().contentWindow.document.getElementById('captureVideo1');
        alert(x.innerHTML);
        if (x!= null)
        {
           alert(x);
           x.addEventListener("click",function() {
            that._captureVideo.apply(that, arguments);
        });
        }
       
       var v2= document.getElementById("captureAudio1");
       if(v2 != null)
       {
           v2.addEventListener("click",function() {
            that._capureAudio.apply(that, arguments);
        });
        }
        var v3= document.getElementById("captureImage1");
        if(v3 != null)
             {
           v3.addEventListener("click",function() {
            that._captureImage.apply(that, arguments);
        });
        }

Tags
General Discussions
Asked by
nav100
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
vaishali
Top achievements
Rank 1
Share this question
or