Dynamic menu calculation via Javascript from an array

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
Bischoff
Beginner
Beginner
Posts: 5
Joined: Tue Jun 01, 2004 10:57 am

Dynamic menu calculation via Javascript from an array

Post by Bischoff »

Hi,
for the following problem I would need your help. I am new to the menu system and also rather new to Javascript. So, I would be happy if somebody could help finding my way.

I am programming an online course. The course data is in XML. It comes to my xsl via an array. The menu structure and all the other data is in an array with several dimensions. It looks like this:

var records = new Array();
var textnr = new Array();
<xsl:for-each select="esys2export/record">
records[<xsl:value-of select="position()"/>] = new Array();
records[<xsl:value-of select="position()"/>]["textnr"] = unescape("<xsl:value-of select="textnr"/>");
records[<xsl:value-of select="position()"/>]["menulevel1"] = unescape("<xsl:value-of select="menulevel1"/>");
records[<xsl:value-of select="position()"/>]["menulevel2"] = unescape("<xsl:value-of select="menulevel2"/>");
records[<xsl:value-of select="position()"/>]["menulevel3"] = unescape("<xsl:value-of select="menulevel3"/>");
records[<xsl:value-of select="position()"/>]["titel"] = unescape("<xsl:value-of select="titel"/>");
records[<xsl:value-of select="position()"/>]["text"] = unescape("<xsl:value-of select="titel2"/>");

</xsl:for-each>

Now I have all I need in the array records(). Lets say I get 10 entries in the array records:

records[textnr][menulevel1][menulevel2][menulevel3][titel][text]

records[1][001][Session 1][Introduction][plain][Some Titel][blabla]
records[2][002][Session 1][Main Part][Goal of Session 1][Some Titel][blabla]
records[3][003][Session 1][Main Part][Let's learn][Some Titel][blabla]
records[4][004][Session 1][Wrap up][Lessons learned][Some Titel][blabla]
records[5][005][Session 2][Introduction][plain][Some Titel][blabla]
records[6][006][Session 2][Main Part][Goal of Session 1][Some Titel][blabla]
records[7][007][Session 2][Main Part][Let's learn][Some Titel][blabla]
records[8][008][Session 2][Wrap up][Lessons learned][Some Titel][blabla]
records[9][009][Good Bye][plain][plain][Some Titel][blabla]
records[10][010][Literature][Books][plain][blabla]
records[11][011][Literature][Websites][plain][blabla]

I now would need a function to calculate the Milonic menus depending on what is in my array for menulevel1, menulevel2 and menulevel3.

Do you have any working code in Javascript. All I found in the forum was PHP what did not help me.

Thanks,
Kerstin
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Hi,

Where is this piece of code from?

Code: Select all

var records = new Array(); 
var textnr = new Array(); 
<xsl:for-each select="esys2export/record"> 
records[<xsl:value-of select="position()"/>] = new Array(); 
records[<xsl:value-of select="position()"/>]["textnr"] = unescape("<xsl:value-of select="textnr"/>"); 
records[<xsl:value-of select="position()"/>]["menulevel1"] = unescape("<xsl:value-of select="menulevel1"/>"); 
records[<xsl:value-of select="position()"/>]["menulevel2"] = unescape("<xsl:value-of select="menulevel2"/>"); 
records[<xsl:value-of select="position()"/>]["menulevel3"] = unescape("<xsl:value-of select="menulevel3"/>"); 
records[<xsl:value-of select="position()"/>]["titel"] = unescape("<xsl:value-of select="titel"/>"); 
records[<xsl:value-of select="position()"/>]["text"] = unescape("<xsl:value-of select="titel2"/>"); 

</xsl:for-each> 
We are currently working on XML based menus but I'd like to know ehere you are declaring the above.

Cheers
Andy
Bischoff
Beginner
Beginner
Posts: 5
Joined: Tue Jun 01, 2004 10:57 am

Post by Bischoff »

Hi, this is my own developed code I have in my little program. I do not know about any of your XML's.

I am declaring the array-code in the Head-section of my XSL-File.

My question was now to an routiene for the menus, some kine of For all....

Kerstin
Post Reply