Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > loop in javascript

Reply
Thread Tools

loop in javascript

 
 
Christopher Brandsdal
Guest
Posts: n/a
 
      07-23-2003
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>");
}



 
Reply With Quote
 
 
 
 
Dave Anderson
Guest
Posts: n/a
 
      07-23-2003
"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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Getting a loop to activate a loop above it Byte Python 4 03-24-2006 03:04 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57