473,498 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fancy Drop Down in JS

1 New Member
I'm a total newbie. I really need help with this script. Its a drop down menu formatted with a CSS. It's not a formatting issue but i can't get the JS to run. I think I'm having issues calling it or something. If you generate the code obviously it'll look screwy since it doesn't have the CSS but the problem is i can't get the menu to collapse or expand. Do I need an onClick statement or something?Here it is. Help!

[HTML]<html>
<head>
<title>j</title>
<link rel="stylesheet" type="text/css" href="sdmenu.css" />
<script type="text/javascript" src="sdmenu.js">
<script type="text/javascript">
// <![CDATA[
var myMenu;
window.onload = function() {
myMenu = new SDMenu("my_menu");
myMenu.init();
};
// ]]>
</script>

</head>
<body>

<div style="float: left" id="my_menu" class="sdmenu">
<div><span>Inventory</span></div>
<div><span>Field Descriptions</span>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventFields.html#Field_Desc" class="submenu">General Fields</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventFields.html#UserTab" class="submenu">User/Location Tab</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventFields.html#CoverageTab" class="submenu">Coverage Tab</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventFields.html#POTab" class="submenu">P.O. Tab</a>
</div>
<div>
<span>Adding a Record</span>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventAddEquip.html#User_Location_tab" class="submenu">User/Location Tab</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventAddEquip.html#Coverage_tab" class="submenu">Coverage Tab</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventAddEquip.html#PO_Info_tab" class="submenu">P.O. Tab</a>
</div>
<div>
<span>Edit/Update Existing Record</span>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventEditRec.html#Transfer_to_different_user:" class="submenu">Transfer to different user</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventEditRec.html#Change_info_other_than_user:" class="submenu">Other Changes</a>
</div>
<div>
<span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/InventDisposeRec.html">Disposing Equipment</a></span>
</div>
<div>
<span>Help Desk</span>
</div>
<div>
<span>Field Descriptions</span>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDFields.html#TicketInfo" class="submenu">Ticket Info</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDFields.html#AssetTag" class="submenu">Asset Tag</a>
<a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDFields.html#Desc_Fields" class="submenu">Description Fields</a>
</div>
<div>
<span> <a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDOpenTicket.html" class="menu1"> Opening a new ticket</a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDUpdateTicket.html" class="menu1"> Updating Open Ticket </a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDCloseTicket.html" class="menu1"> Closing a Ticket</a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/HDKnowBase.html" class="menu1"> Knowledge base/Searching for records</a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/TaskPanel.html" class="menu1"> Task Panel Button Descriptions</a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/BasicCommands.html" class="menu1"> Filemaker Tips and Tricks</a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/AdminTools.html" class="menu1" onClick="showHide('Admin_menu')"> Admin Tools</a></span></div>
<div><span><a href="http://webcontent.courtnet.org/w1_www/courts/DistrictOffices/6thDistrict/ops/Instructions/UCICS/default.html" class="menu1">Main Page</a></span></div>
</div>

</body>
</html>
[/HTML]

the JS file is:

Expand|Select|Wrap|Line Numbers
  1. var SDMenu;
  2. SDMenu = new SDMenu("my_menu");
  3.  
  4. function SDMenu(id) {
  5.     if (!document.getElementById || !document.getElementsByTagName)
  6.         return false;
  7.     this.menu = document.getElementById(id);
  8.     this.submenus = this.menu.getElementsByTagName("div");
  9.     this.remember = true;
  10.     this.speed = 3;
  11.     this.markCurrent = true;
  12.     this.oneSmOnly = false;
  13. }
  14. SDMenu.prototype.init = function() {
  15.     var mainInstance = this;
  16.     for (var i = 0; i < this.submenus.length; i++)
  17.         this.submenus[i].getElementsByTagName("a")[0].onclick = function() {
  18.             mainInstance.toggleMenu(this.parentNode);
  19.         };
  20.     if (this.markCurrent) {
  21.         var links = this.menu.getElementsByTagName("a");
  22.         for (var i = 0; i < links.length; i++)
  23.             if (links[i].href == document.location.href) {
  24.                 links[i].className = "current";
  25.                 break;
  26.             }
  27.     }
  28.     if (this.remember) {
  29.         var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
  30.         var match = regex.exec(document.cookie);
  31.         if (match) {
  32.             var states = match[1].split("");
  33.             for (var i = 0; i < states.length; i++)
  34.                 this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
  35.         }
  36.     }
  37. };
  38. SDMenu.prototype.toggleMenu = function(submenu) {
  39.     if (submenu.className == "collapsed")
  40.         this.expandMenu(submenu);
  41.     else
  42.         this.collapseMenu(submenu);
  43. };
  44. SDMenu.prototype.expandMenu = function(submenu) {
  45.     var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
  46.     var links = submenu.getElementsByTagName("a");
  47.     for (var i = 0; i < links.length; i++)
  48.         fullHeight += links[i].offsetHeight;
  49.     var moveBy = Math.round(this.speed * links.length);
  50.  
  51.     var mainInstance = this;
  52.     var intId = setInterval(function() {
  53.         var curHeight = submenu.offsetHeight;
  54.         var newHeight = curHeight + moveBy;
  55.         if (newHeight < fullHeight)
  56.             submenu.style.height = newHeight + "px";
  57.         else {
  58.             clearInterval(intId);
  59.             submenu.style.height = "";
  60.             submenu.className = "";
  61.             mainInstance.memorize();
  62.         }
  63.     }, 30);
  64.     this.collapseOthers(submenu);
  65. };
  66. SDMenu.prototype.collapseMenu = function(submenu) {
  67.     var minHeight = submenu.getElementsByTagName("div")[0].offsetHeight;
  68.     var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
  69.     var mainInstance = this;
  70.     var intId = setInterval(function() {
  71.         var curHeight = submenu.offsetHeight;
  72.         var newHeight = curHeight - moveBy;
  73.         if (newHeight > minHeight)
  74.             submenu.style.height = newHeight + "px";
  75.         else {
  76.             clearInterval(intId);
  77.             submenu.style.height = "";
  78.             submenu.className = "collapsed";
  79.             mainInstance.memorize();
  80.         }
  81.     }, 30);
  82. };
  83. SDMenu.prototype.collapseOthers = function(submenu) {
  84.     if (this.oneSmOnly) {
  85.         for (var i = 0; i < this.submenus.length; i++)
  86.             if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
  87.                 this.collapseMenu(this.submenus[i]);
  88.     }
  89. };
  90. SDMenu.prototype.expandAll = function() {
  91.     var oldOneSmOnly = this.oneSmOnly;
  92.     this.oneSmOnly = false;
  93.     for (var i = 0; i < this.submenus.length; i++)
  94.         if (this.submenus[i].className == "collapsed")
  95.             this.expandMenu(this.submenus[i]);
  96.     this.oneSmOnly = oldOneSmOnly;
  97. };
  98. SDMenu.prototype.collapseAll = function() {
  99.     for (var i = 0; i < this.submenus.length; i++)
  100.         if (this.submenus[i].className != "collapsed")
  101.             this.collapseMenu(this.submenus[i]);
  102. };
  103. SDMenu.prototype.memorize = function() {
  104.     if (this.remember) {
  105.         var states = new Array();
  106.         for (var i = 0; i < this.submenus.length; i++)
  107.             states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
  108.         var d = new Date();
  109.         d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
  110.         document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
  111.     }
  112. };
Jun 21 '07 #1
1 6939
pbmods
5,821 Recognized Expert Expert
Heya, priscbean.

Ewww. Here's some extra code tags in case you ran out:

[/code][/code][/code][/code]
[code][code][code][code]

Just drop them into your next post in reverse order, and you'll be all set!

Are you getting an error, or is the code just not executing? Try adding some alert statements in key locations to verify that your code is getting run.
Jun 21 '07 #2

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

Similar topics

6
2451
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
2
11009
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
1
2880
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
3
6137
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
12594
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
1
2485
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
7
2422
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
4
9270
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
7326
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.