Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-22
2
Medium Priority
?
420 Views
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 elem.id 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?

javascript:

      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
        {
                  document.writeln(formElements[i].id);
            
            if(formElements[i] != null && formElements[i].substring(0,3)=="mnu")
            {
                  document.writeln(formElements[i].id);
                  if(elem.id == formElements[i].id)
                  {
                        //elem.style.display = 'block';
                        //elem.style.visibility = 'visible';
                        elem.style.display ='none';      
                        elem.style.visibility ='hidden';
                  }
                  else
                  {
                        formElements[i].style.display = 'block';
                        formElements[i].style.visibility = 'visible';
                        //elem.style.display ='none';      
                        //elem.style.visibility = 'hidden';
                  }
            }
      }
  }


parts of html:

<body>
            <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>
                                    </TD>

0
Comment
Question by:bswiftly
2 Comments
 
LVL 1

Author Comment

by:bswiftly
ID: 12655577
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 asp.net...which 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]);
            if(tmpElem)
            {
            tmpElem.style.display ='none';      
            tmpElem.style.visibility ='hidden';
            }
      }
       elem.style.display = 'block';
       elem.style.visibility = 'visible';
}

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12889405
Closed, 50 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

810 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