/    Sign up×
Community /Pin to ProfileBookmark

Newbie here in need of a little JS/XML help

I am having a load of problems trying to build a script to write a cascading menu. The idea is that the javascript loops through an XML file and builds the menu on page load.

I am new to webdesign and am having to learn advanced HTML and javascript as I go so I am having a very difficult time with this…

I need it to write the main menu using the <name> tag under <menu> and build the drop down menus using the <sub> tag data. My biggest problem is I cant seem to find the correct syntax for looping through the DOM without having to call a tag by name, and transitioning from a parent to child.

Im trying to build it this way so after it is done personel here can just edit the XML file to change the site’s menu.

And one more question, should the name and link of a menu entry be listed in child tags like I have it or would it be better to list them as attributes?

Any and all help will be greatly appreciated…I have several books im going through also, but im having to swallow a lot at once and complete this on a deadline.

An example of the XML file is this:

[code]
<prinavbar>

<menu>
<name>Home</name>
<link>underconst.html</link>
</menu>

<menu>
<name>About XXXX</name>
<link>underconst.html</link>
<sub>
<name>Principle Notes</name>
<link>underconst.html</link>
</sub>
<sub>
<name>History</name>
<link>underconst.html</link>
</sub>
<sub>
<name>Philosophy and Mission</name>
<link>underconst.html</link>
</sub>
<sub>
<name>Direction and Map</name>
<link>underconst.html</link>
</sub>
<sub>
<name>Campus Information</name>
<link>underconst.html</link>
</sub>
<sub>
<name>Catalog</name>
<link>underconst.html</link>
</sub>
</menu>

</prinavbar>
[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Avanesov spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...