Link to home
Start Free TrialLog in
Avatar of AWSHelpdesk
AWSHelpdesk

asked on

getElementById not working on master page

I have a user control which has a document.getElementById call and it works on all of the pages I put the user control on except when I use the user control on a content page that uses a master page then I get the error document.getElementById is not a function?

 I don't have any spelling errors or anything like that because the control works fine when it is not on a master page page
This is the javascript function within the user control where the error is occuring on Master Page content pages only
 
    function ClearNoTab() {
        //alert('called');
        var noTabsDiv = document.getElementById('noTab');
        if (noTabsDiv != null) {
            noTabsDiv.style.display = "none";
        }
    }
 
  This is the actual object;
 
  <div id="noTab" style="display: none;">
 
Test<asp:Literal ID="litNominatedArticleNoTab" runat="server"></asp:Literal> </div>

Open in new window

Avatar of HonorGod
HonorGod
Flag of United States of America image

Check to see if you have multiple document elements that have "noTab" as the id attribute.
wait a minute... I just re-read the statement again.  You get an error "document.getElementById" is not a function?  Wow, that's strange.

Can you provide the whole page?

Is the code where the document.getElementById() call exists with a <script> clause?

What does the <script> tag look like?

Does it look like?
<script type='text/javascript'>
 
or 
 
<script language='JavaScript'>

Open in new window

Hi! By using MasterPages, the control names are renderd differently. The control id is prefixed by ctl01_ctl02...

Something like

     document.getElementById('ctl00_ContentPlaceHolder1_Control name').value

or you want to use this

     document.getElementById("<%=Controlname.ClientID %>").value
ASKER CERTIFIED SOLUTION
Avatar of RobbP
RobbP
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial