ASP.NET  + javascript:  can't recognize form elements?

Posted on 2004-11-22
Last Modified: 2008-02-01
I am trying to access form elements in order to hide show div tags, the hide show part is easy but I keep getting a null reference.. it doesn't see my form!

When I write out document.forms.length  the resulting value is 0!!

when i write out after it is set, it will print out the appropriate element id that I had passd in.. so why does it sometimes know the element is there but can not find my form name?


      function ShowConfiguration(id)
      var elem = self.document.getElementById(id);
        var formElements = document.frmQuery.elements; //  becomes null.
      for(var i=0; i <  formElements.length; i++) //errors here saying formElements is null
            if(formElements[i] != null && formElements[i].substring(0,3)=="mnu")
                  if( == formElements[i].id)
                        // = 'block';
                        // = 'visible';
                        formElements[i].style.display = 'block';
                        formElements[i].style.visibility = 'visible';
                        // ='none';      
                        // = 'hidden';

parts of html:

            <form name="frmQuery" method="post" action="mainChart.aspx" id="frmQuery">

this form has some nested div tags who's id's will be passed by the onclick event of other buttons.

button code:
<TD><A class="menuLink" id="hypDataPullTimes" onclick="javascript:ShowConfiguration('mnuTransferTimes');"
                                                href="#">Data Pull Times</A>

Question by:bswiftly
    LVL 1

    Author Comment

    well I stared at that solution for a day and decided to do a work around.. definately not a scalable piece of javascript but this is it:

    And I'm not sure why I had to put this at the end outside of all the HTML, but i got different results outside the HEAD tag as to within it. I thought Head Tag code was rendered first ?  ah well.. I'll leave this question open in case anyone can substitude mnuElems.length in the following code for document.formName.elements, and then you will get points.    Remember..this is is I think the big problem here.. damn M$.

     function ShowConfiguration(id)
          var elem = document.getElementById(id);
          var mnuElems = ["mnuTransferTimes","mnuSingleRetId"];
          var tmpElem;
          for(var i = 0; i<mnuElems.length;i++)
                tmpElem = document.getElementById(mnuElems[i]);
  = 'block';
  = 'visible';


    Accepted Solution

    Closed, 50 points refunded.

    Community Support Moderator
    Experts Exchange

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now