Javascript getElementByID returns null

3 posts, 0 answers
  1. nav100
    nav100 avatar
    48 posts
    Member since:
    Dec 2010

    Posted 27 May 2012 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 May 2012 Link to this post

    Hi,

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

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. vaishali
    vaishali avatar
    2 posts
    Member since:
    Mar 2016

    Posted 18 Mar Link to this post

    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);
            });
            }

Back to Top