473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Add third level to JavaScript 2-level menu

Stang02GT
1,208 Expert 1GB
Hello,

I am creating a menu and a friend gave me some code to play with and i have gotten the menu just how i want it except of one thing. The code that generates the menu is only set up for 2 levels. You mouse over the a section of the menu and a sub section with display giving you options regarding the previouse level.

I need to be able to have a 3rd level generate from the 2nd level.


This menu is comprised of
an HTML file
JavaScriptfile
an a CSS file.

If anyone would be willing to take a look at these files and help me out that would be great!

Thank you very much.
Nov 30 '07 #1
19 2195
gits
5,390 Expert Mod 4TB
hi ...

is it too much code to be posted here? ... in case its not then please post it or post a link to a testpage ...

kind regards
Nov 30 '07 #2
Stang02GT
1,208 Expert 1GB
there are three different files but here is the Java script file that i need to modify.




Expand|Select|Wrap|Line Numbers
  1. var cssmenuids=["cssmenu1"] //Enter id(s) of CSS Horizontal UL menus, separated by commas
  2. var csssubmenuoffset=-1 //Offset of submenus from main menu. Default is 0 pixels.
  3.  
  4. function createcssmenu2(){
  5. for (var i=0; i<cssmenuids.length; i++){
  6.   var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
  7.     for (var t=0; t<ultags.length; t++){
  8.             ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
  9.         var spanref=document.createElement("span")
  10.             spanref.className="arrowdiv"
  11.             spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"
  12.             ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
  13.         ultags[t].parentNode.onmouseover=function(){
  14.                     this.style.zIndex=100
  15.         this.getElementsByTagName("ul")[0].style.visibility="visible"
  16.                     this.getElementsByTagName("ul")[0].style.zIndex=0
  17.         }
  18.         ultags[t].parentNode.onmouseout=function(){
  19.                     this.style.zIndex=0
  20.                     this.getElementsByTagName("ul")[0].style.visibility="hidden"
  21.                     this.getElementsByTagName("ul")[0].style.zIndex=100
  22.         }
  23.     }
  24.   }
  25. }
  26.  
  27. if (window.addEventListener)
  28. window.addEventListener("load", createcssmenu2, false)
  29. else if (window.attachEvent)
  30. window.attachEvent("onload", createcssmenu2)
Dec 2 '07 #3
Stang02GT
1,208 Expert 1GB
Would it be easier if i compressed the the files and e-mailed them?
Dec 5 '07 #4
acoder
16,027 Expert Mod 8TB
Why not just post the HTML and CSS for the menu only?
Dec 5 '07 #5
Stang02GT
1,208 Expert 1GB
Here is the CSS Code

Expand|Select|Wrap|Line Numbers
  1. }
  2.  
  3. /*Top level menu link items style*/
  4. .horizontalcssmenu ul li a{
  5. display: block;
  6. width: 120px; /*Width of top level menu link items*/
  7. padding: 2px 8px;
  8. border: 1px solid #202020;
  9. border-left-width: 0;
  10. text-decoration: none;
  11. background: url(untitled.bmp) center center repeat-x;
  12. color: white;
  13. font: bold 13px Tahoma;
  14. }
  15.  
  16. /*Sub level menu*/
  17. .horizontalcssmenu ul li ul{
  18. left: 0;
  19. top: 0;
  20. border-top: 1px solid #202020;
  21. position: absolute;
  22. display: block;
  23. visibility: hidden;
  24. z-index: 100;
  25. }
  26.  
  27. /*Sub level menu list items*/
  28. .horizontalcssmenu ul li ul li{
  29. display: inline;
  30. float: none;
  31. }
  32.  
  33.  
  34. /* Sub level menu links style */
  35. .horizontalcssmenu ul li ul li a{
  36. width: 160px; /*width of sub menu levels*/
  37. font-weight: normal;
  38. padding: 2px 5px;
  39. background: url(untitled1.bmp) center center repeat-x;
  40. border-width: 0 1px 1px 1px;
  41. }
  42.  
  43. .horizontalcssmenu ul li a:hover{
  44. background: url(untitled1.bmp) center center repeat-x;
  45. }
  46.  
  47. .horizontalcssmenu ul li ul li a:hover{
  48. background: url(untitled2.bmp) center center repeat-x;
  49. }
  50.  
  51. .horizontalcssmenu .arrowdiv{
  52. position: absolute;
  53. right: 0;
  54. background: transparent url(menuarrow.gif) no-repeat center left;
  55. }
  56.  
  57. * html p#iepara{ /*For a paragraph (if any) that immediately follows menu, add 1em top spacing between the two in IE*/
  58. padding-top: 1em;
  59. }
Dec 5 '07 #6
Stang02GT
1,208 Expert 1GB
The first file code that I posted is the JavaScript that needs to be edited, thats where i'm getting caught up at.
Dec 5 '07 #7
acoder
16,027 Expert Mod 8TB
Lines 8-22 set up for the main uls. To apply for sub-levels, you would need to get the uls again inside each ul element and apply the same code - the offset will probably be different.

Post the HTML code too.
Dec 5 '07 #8
Stang02GT
1,208 Expert 1GB
Ok, how would i change it to make the third level open to the right opposed to strait down?

Expand|Select|Wrap|Line Numbers
  1. </head>
  2. <body>
  3.  
  4. <div class="horizontalcssmenu">
  5. <ul id="cssmenu1">
  6. <li style="border-left: 1px solid #202020;"><a href="http://www.javascriptkit.com/">Home</a></li>
  7. <li><a href="http://www.javascriptkit.com/cutpastejava.shtml" >Free JS</a></li>
  8. <li><a href="http://www.javascriptkit.com/">JS Tutorials</a></li>
  9. <li><a href="#">References</a>
  10.     <ul>
  11.     <li><a href="http://www.javascriptkit.com/jsref/">JS Reference</a></li>
  12.         <ul>
  13.             <li><a href="http://www.javascriptkit.com/jsref/">JS Reference</a></li>
  14.             <li><a href="http://www.javascriptkit.com/domref/">DOM Reference</a></li>
  15.             <li><a href="http://www.javascriptkit.com/dhtmltutors/cssreference.shtml">CSS Reference</a></li>
  16.             </ul>
  17.  
  18.     <li><a href="http://www.javascriptkit.com/domref/">DOM Reference</a></li>
  19.     <li><a href="http://www.javascriptkit.com/dhtmltutors/cssreference.shtml">CSS Reference</a></li>
  20.     </ul>
  21. </li>
  22. <li><a href="http://www.javascriptkit.com/howto/">web Tutorials</a></li>
  23. <li><a href="#">Resources</a>
  24.     <ul>
  25.     <li><a href="http://www.dynamicdrive.com">Dynamic HTML</a></li>
  26.     <li><a href="http://www.codingforums.com">Coding Forums</a></li>
  27.     <li><a href="http://www.cssdrive.com">CSS Drive</a></li>
  28.     <li><a href="http://www.dynamicdrive.com/style/">CSS Library</a></li>
  29.     <li><a href="http://tools.dynamicdrive.com/imageoptimizer/">Image Optimizer</a></li>
  30.     <li><a href="http://tools.dynamicdrive.com/favicon/">Favicon Generator</a></li>
  31.     </ul>
  32. </li>
  33. </ul>
  34. <br style="clear: left;" />
  35. </div>
  36.  
  37. <p id="iepara">Rest of content here</p>
  38.  
  39.  
  40. </body>
  41. </html>

This is just a dummy script but the step up is the same. The bold section is an example of a third level, that when scrolled over opens strait down, i need it to open to the right.
Dec 5 '07 #9
acoder
16,027 Expert Mod 8TB
Ok, how would i change it to make the third level open to the right opposed to strait down?
You need to recognise it as different from the rest of the lists. You could check that the parentNode is a UL element. If it is, it's a third level list. Take the dimensions of the already open menu level and set the left to the left + width.
Dec 6 '07 #10
Stang02GT
1,208 Expert 1GB
You need to recognise it as different from the rest of the lists. You could check that the parentNode is a UL element. If it is, it's a third level list. Take the dimensions of the already open menu level and set the left to the left + width.

I have been tinkering with this since last night and i can't figure it out. I understand what you are saying i just am having trouble putting the code in the right places. If that makes since.

Could you help me out a little more?
Dec 6 '07 #11
Stang02GT
1,208 Expert 1GB
I guess to make things easier if anyone can help me i am Trying to modify the menu from this site...


http://www.javascriptkit.com/script/...stopmenu.shtml


i just need to add a thrid level that opens to the right
Dec 7 '07 #12
acoder
16,027 Expert Mod 8TB
Is it OK if I offer you this instead (you can modify the CSS to make it look better)? If not, I'll see what changes can be made to this menu.

PS. changed the thread title to give it a better description.
Dec 10 '07 #13
Stang02GT
1,208 Expert 1GB
I can get the third level of the menu to open with all of the correct links and fields, is there something i can add to the HTML that would make that third level open to the right or left when it is scrolled over? Or is there something i can add to the javascript?
Dec 13 '07 #14
acoder
16,027 Expert Mod 8TB
I can get the third level of the menu to open with all of the correct links and fields, is there something i can add to the HTML that would make that third level open to the right or left when it is scrolled over? Or is there something i can add to the javascript?
Well, in that case, set the style.left to be equal to the style.left property of the second level + the width of the second level menu. This would open it to the right assuming the 'style.top' setting is how you want it.
Dec 13 '07 #15
Stang02GT
1,208 Expert 1GB
acoder,

I have something to run by you, let me know what you think/if this is possible.

Could i create a javascript event in the HTML code in the two sections i need the menu to open right?

I could do something like a onMouseover event?
Dec 14 '07 #16
Stang02GT
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <A HREF="http://www.thescripts.com"
  2. onMouseOver="openright='openright; return true">TSDN</A> 
i know this is probably way off but would it look something like this?
Dec 14 '07 #17
acoder
16,027 Expert Mod 8TB
Could i create a javascript event in the HTML code in the two sections i need the menu to open right?

I could do something like a onMouseover event?
You could, but there's no need to. You just need to find the third level menu elements and set the left/top properties.

Set it with, e.g.:
Expand|Select|Wrap|Line Numbers
  1. ultag.style.left = parseInt(ultag.parentNode.style.left) + parseInt(ultag.parentNode.style.width) + "px"
You'll need to put the UL sub-sub menu element within the LI tag. To find the third level, usesomething like li.getElementsByTagName("ul") or even ultags[t].getElementsByTagName("ul").
Dec 17 '07 #18
Stang02GT
1,208 Expert 1GB
I have figured out a solution to my problem i added items to the CSS file for the third level of the menu. Here is what i added ...


Expand|Select|Wrap|Line Numbers
  1. /*3rd level menu*/
  2. .horizontalcssmenu ul li ul li ul{
  3. left: 0;
  4. top: 0;
  5. border-top: 0px solid #202020;
  6. position: absolute;
  7. left: 30px; /*this is the offset for the sub sub-menu to allow the sub-menu to be seen*/
  8. display: block;
  9. visibility: hidden;
  10. z-index: inherit;
  11. }
  12.  
  13. /*3rd  menu list items*/
  14. .horizontalcssmenu ul li ul li ul li{
  15. display: inherit;
  16. float: right;
  17. }
  18.  
  19.  
  20. /*3rd  menu links style */
  21. .horizontalcssmenu ul li ul li ul li a{
  22. width:120px; /*width of sub menu levels*/
  23. display:block;
  24. font-weight: normal;
  25. padding: 2px 2px;
  26. background:  url(untitled.bmp) center center repeat-x;
  27. border-width: 0 1px 1px 1px;
  28. }
Dec 21 '07 #19
acoder
16,027 Expert Mod 8TB
I have figured out a solution to my problem i added items to the CSS file for the third level of the menu.
Yes, that's an alternative way and probably better too. Glad you managed to solve it.
Dec 22 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: johkar | last post by:
I need to document.write out a select list populated with the dates for the first and third Wednesday of each month. How do I get to the actual days? <select name="mySelect"> <option value="Oct...
0
by: David | last post by:
First, a question. Is there a way to keep VS.NET from red lining elements from third party controls with an error message that says 'the active schema does not support the element ****'? ...
1
by: A | last post by:
Hi, I am trying to set up a DataGrid to do inline editing. Good God this is taking forever, I only have about five columns of data. Does anyone recommend a third party that's faster or should...
6
by: Ben Finney | last post by:
Howdy all, I'm improving an existing application that's partly written using Python and the standard library. Many of the improvements I want to make can be done by using third-party free...
4
by: m11533 | last post by:
I am developing a large application with Visual Studio .NET 2003 using C#. We recently added a new third party product with a native .NET library. I want to place this third party product's dll in...
1
by: amit | last post by:
Hi all, I'm totally new to 3rd party cookies! 1)would one please tell me what they are? 2)how to make IE to detect them? 3)how can I trick IE or FF not to see them? (if possible!)
5
by: Eric Layman | last post by:
Hi, I noticed that PHP have the ability to create PDF files without using any third partty componentys. Most notably is via FPDF. It generates PDF by using "pdf markups" / or ghostscripts I...
37
by: josh | last post by:
Hi, any idea about what third-party library can I use to improve my Javascript UI YUI ? Google ? script.aculo.us ? or others?
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.