473,378 Members | 1,156 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,378 software developers and data experts.

loop in javascript

Hi!

I have a menu-system in JavaScript.

The menu is displayed by two js functions ( DrawMenuBar and DrawSubMenu ).
the first function displays the parent items, and includes the other
function to display sub items if it exists.
I wanted to add one more child. that means the menu contained 3 levels.
To display the third sub item, I made DrawSubMenu run a new
function(DrawSubSubMenu). That way the menu was able to have 3 levels.

My question:
If I wanted to make my menu lets say 10 levels..... Is it any good way to
loop the function? Or is it best for me to just write a new subsubsub
function and so on?
One of the inportant things about the menu is hat it only expand's the item
you have selected.(!)

Thanks a lot in advance.

best regards Christopher

THIS IS MY CODE:

////////////////////////////////////////////////////////////////////////////
///////////////////
function DrawMenuBar(oSite, oRootNode, oRequestedNode)
{
if (oSite == null || oRootNode == null)
return;

var i=0;
var oFirstLevelNode = null;

Response.Write("<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\"
WIDTH=\"140\">");
while ((oFirstLevelNode = oRootNode.GetChildByOrder(i++)) != null)
{
Response.Write("<TR><TD CLASS=\"normal\" HEIGHT=\"21\">");

var sImgNormal = oFirstLevelNode.GetImageMenuNormal();

// Display images menu
if (sImgNormal != "")
{
if (oFirstLevelNode.IsLink())
{
Response.Write("<A HREF=" + oSite.GetNodeLink(oFirstLevelNode,true));

if (oFirstLevelNode.IsEqualOf(oRequestedNode) ||
oFirstLevelNode.IsAncestorOf(oRequestedNode))
Response.Write("><IMG SRC=\"" + oFirstLevelNode.GetImageMenuActive()
+ "\"");
else
{
Response.Write(" ONMOUSEOVER=\"document.menu" + i + ".src='" +
oFirstLevelNode.GetImageMenuMouseOver() + "'\"");
Response.Write(" ONMOUSEOUT=\"document.menu" + i + ".src='" +
oFirstLevelNode.GetImageMenuNormal() + "'\">");
Response.Write("<IMG NAME=\"menu" + i + "\" SRC=\"" +
oFirstLevelNode.GetImageMenuNormal() + "\"");
}

Response.Write(" BORDER=\"0\" ALIGN=\"top\"></A>");
}
else
Response.Write("<IMG SRC=\"" + oFirstLevelNode.GetImageMenuNormal()
+"\">");
}
// Display text menu
else
{
if (oFirstLevelNode.IsLink())
{
Response.Write("&nbsp;<A HREF=" +
oSite.GetNodeLink(oFirstLevelNode,true) + ">");
if (oFirstLevelNode.IsEqualOf(oRequestedNode) ||
oFirstLevelNode.IsAncestorOf(oRequestedNode))
Response.Write("<FONT COLOR=\"#F06B00\"><B>" +
oFirstLevelNode.GetTextMenu() + "</B></FONT>");
else
Response.Write("<B>" + oFirstLevelNode.GetTextMenu() + "</B>");

Response.Write("</A>");
}
else
Response.Write("&nbsp;<B>" + oFirstLevelNode.GetTextMenu() + "</B>");
}

Response.Write("</TD></TR>");

// Display sub-menu for selected menu
if (oFirstLevelNode.HasChilds() &&
(oFirstLevelNode.IsAncestorOf(oRequestedNode) ||
oFirstLevelNode.IsEqualOf(oRequestedNode)))
DrawSubMenu(oSite, oFirstLevelNode, oRequestedNode);
}

Response.Write("</TABLE>");
}

////////////////////////////////////////////////////////////////////////////
/////////////////
function DrawSubMenu(oSite, oNode, oRequestedNode)
{
if (oSite == null || oNode == null)
return;

// Display only text menu

var oSecondLevelNode = null;
var i=0;

Response.Write("<TR><TD><IMG SRC=\"./images/1px_t.gif\" WIDTH=\"1\"
HEIGHT=\"5\"></TD></TR>");

while ((oSecondLevelNode = oNode.GetChildByOrder(i++)) != null)
{
Response.Write("<TR><TD CLASS=\"normal\" HEIGHT=\"21\">");

if (oSecondLevelNode.IsLink() &&
!oSecondLevelNode.IsEqualOf(oRequestedNode))
{
Response.Write("<IMG SRC=\"./images/1px_t.gif\" WIDTH=\"12\"
HEIGHT=\"1\">");
Response.Write("<A HREF=" + oSite.GetNodeLink(oSecondLevelNode,true) +
">");
Response.Write(oSecondLevelNode.GetTextMenu());
Response.Write("</A>");
}
else
{
Response.Write("<IMG SRC=\"./images/arrow01.gif\">");
Response.Write(oSecondLevelNode.GetTextMenu());
}

Response.Write("</TD></TR>");
// Display subsub-menu for selected menu
if (oSecondLevelNode.HasChilds() &&
(oSecondLevelNode.IsAncestorOf(oRequestedNode) ||
oSecondLevelNode.IsEqualOf(oRequestedNode)))
DrawSubSubMenu(oSite, oSecondLevelNode, oRequestedNode);
}

Response.Write("<TR><TD><IMG SRC=\"./images/1px_t.gif\" WIDTH=\"1\"
HEIGHT=\"10\"></TD></TR>");
}
////////////////////////////////////////////////////////////////////////////
////////////////////
function DrawSubSubMenu(oSite, oNode, oRequestedNode)
{
if (oSite == null || oNode == null)
return;

// Display only text menu

var oThirdLevelNode = null;
var i=0;

Response.Write("<TR><TD><IMG SRC=\"./images/1px_t.gif\" WIDTH=\"1\"
HEIGHT=\"5\"></TD></TR>");

while ((oThirdLevelNode = oNode.GetChildByOrder(i++)) != null)
{
Response.Write("<TR><TD CLASS=\"normal\" HEIGHT=\"21\">");

if (oThirdLevelNode.IsLink() &&
!oThirdLevelNode.IsEqualOf(oRequestedNode))
{
Response.Write("<IMG SRC=\"./images/1px_t.gif\" WIDTH=\"12\"
HEIGHT=\"1\">");
Response.Write("<A HREF=" + oSite.GetNodeLink(oThirdLevelNode,true) +
">");
Response.Write(oThirdLevelNode.GetTextMenu());
Response.Write("</A>");
}
else
{
Response.Write("<IMG SRC=\"./images/arrow01.gif\">");
Response.Write(oThirdLevelNode.GetTextMenu());
}

Response.Write("</TD></TR>");
}

Response.Write("<TR><TD><IMG SRC=\"./images/1px_t.gif\" WIDTH=\"1\"
HEIGHT=\"10\"></TD></TR>");
}

Jul 19 '05 #1
1 2936
"Christopher Brandsdal" wrote:

I have a menu-system in JavaScript...

...If I wanted to make my menu lets say 10 levels..... Is
it any good way to loop the function? Or is it best for me
to just write a new subsubsub function and so on?
One of the inportant things about the menu is hat it only
expand's the item you have selected.(!)


Menu/submenu systems are tree structures, and thus are well-suited for
recursion. I would avoid loops entirely, and I would *definitely* use a
single "function" (I would most likely use a constructor) for establishing
all submenus.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fawke101 | last post by:
Hi There, I have a table with 3 rows. 1st has the table/column headers, 2nd contains the column data and the 3rd is where the loop for the SQL statement lies. I also have a JS sort function on...
1
by: Knocked Wood | last post by:
Hi, I looked around and can't find anything on this at all and can not get it to work for IE. I'm trying to loop multiple sounds on a game, with three unique variables, when a link is clicked....
2
by: bunnyman | last post by:
I have a for each loop in javascript, of which I need to output to an ASP array. unfortunantly not too familiar with javascript.. the loop is for items ordered in a shopping cart. they are...
23
by: Mark Anderson | last post by:
A 'for' loop takes 3 arguments (initialize; test; increment). The 'test' must equate as true or false This doesn't work... x = 5; for (y=1; (y==5); y+=1) { alert(x * y); } ...nor does... x...
3
by: Patrick Sullivan | last post by:
In this for loop, IE skips over the animation function until the end of the loop and only aninmates the last phrase. Firefox does it right. Loop is right below, entire script is below that. This...
14
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure...
12
by: usa-99 | last post by:
Hi there I have following function which is called on load of page. function checkFieldContent(form) { var field; for(i = 0; i < form.elements.length; i++) { field = form.elements; if...
2
by: mrjoka | last post by:
hi experts, i'm developing a page in ASP but i'm doing also some javascript insode the page. i'm creating a frame and i want to loop this frame with a duplicateloop function so the form will be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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
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.