Jump to content


Photo

Javascript accordion menu


  • Please log in to reply
1 reply to this topic

#1 Bouzy210

Bouzy210

    Jedi In Training

  • Members
  • PipPip
  • 434 posts
  • Gender:Male

Posted 30 May 2009 - 11:57 AM

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...

<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...

<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?

#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 31 May 2009 - 10:42 PM

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).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users