Ask a Question related to ASP, Design and Development.

  1. #1

    Default 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>");
    }



    Christopher Brandsdal Guest

  2. Similar Questions and Discussions

    1. javascript array and loop question
      I'm passing in a comma delimited list as a parameter to a function. Ex. the argument passed in holds the following values: 1, 2, 3, 4, 5, I need...
    2. Javascript img declaration loop
      Is it possible to create a loop to create a series of new images, rather than explicitly declaring each. So, rather than the following two lines...
    3. Film loop rollovers working with tell sprite, but only if Loop is checked
      on mouseWithin me cursor 280 tell sprite 40 --the sprite containing the film loop sprite(60).member = member("networkmapsbuttonroll") --swapping...
    4. Urgent: Repeat loop and Film loop clash!
      Hi All, Scenario I have a script running in which the spelling which was typed in by the student is corrected. The alphabets are moved to...
    5. Help with loop inside loop and mysql queries
      Hi List. I cannot see my error: I have relation tables setup. main id entity_name main_type etc etc date_in 1 test type1 x y 2003-06-02...
  3. #2

    Default Re: loop in javascript

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


    Dave Anderson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139