Help - Search - Members - Calendar
Full Version: Javascript accordion menu
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
Bouzy210
Hello I have created some javascript to make an accordion menu and it works when I only have one menu I want to expand like this code...

CODE
<a href="java script:runAccordion('block','html')">HTML/XHTML </a>
  
   <div id="html" name="html">
   some text
   </div>
  
   <script language="JavaScript" type="text/javascript">
   <!--
   function runAccordion(x) {
      var y = document.getElementById('chord');
      y.style.display = x;
   }
   // -->
   </script>


but once I try to add a parameter or variable to the function runAccordion to make it so I can have multiple menus it doesn't work...

CODE
<a  href="java script:runAccordion('block','html')">HTML/XHTML </a>
  
   <div id="html" name="html">
   some text
   </div>
  
   <a href="java script:runAccordion('block','css')">CSS</a>
  
   <div id="css" name="css">
   some more text
   </div>
  
   <script language="JavaScript" type="text/javascript">
   <!--
   function runAccordion(x,z) {
      var y = document.getElementById(z);
      y.style.display = x;
   }
   // -->
   </script>


Could you please explain why this code doesn't work?
rc69
You say the first block of code you provided works right? But i don't see a #chord element anywhere in the code you provided. Is there something you left out?

The second block should work regardless of the first block, though i would recommend you avoid using both "id" and "name" attributes. I'm not sure if that was ever a recommendation, but now all you should use is "id" unless you have a specific need for "name" (i.e. in a form).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.