Board Logo

JavaScript Error: MENU_ITEMS is Undefined
Snowman - 12/8/2003 at 01:40 AM

Ive installed the menu script into an oscommerce site and i cat seem to get it to work.

I constantly get an error saying that MENU_ITEMS is undefined.

any ideas as to what may be causing this???

tigra - 12/13/2003 at 03:03 AM

This kind of error is reported when JavaScript tries to use the variable which is not correctly defined. Possible reasons of the problem are:

1. Name of the variable in configuration file is different from the name of variable passed to menu constructor. I.e. you have MENU_ITEMS1 in menu_items.js file but MENU_ITEMS2 in new menu statement in HTML file

2. File is not linked correctly to the page so JavaScript can't see that variable. I.e. you link to menu_items1.js and structure is defined in menu_items2.js or you link to menu_items.js and file is actually at /javascripts/menu_items.js or file is in the directory with limited or no access allowed. Check web server's log file for broken links reports (response status 404) or access denied (response status 403)

3. There is syntax error in items structure definition i.e. string(s) are not quoted properly, missing or extra brackets, missing or extra commas, etc. To check if problem is caused by syntax error comment out menu initialization ('new menu' statement) but leave configuration files linked. If you still receive JavaScript error then you should check the syntax of configuration files.

Now about your particular case: I've removed all responses from this thread as they don't lead to the solution. Maybe it's rude but I prefer to save readers from confusing reading. HTML errors can cause the problems but they don't result in 'variable is undefined' errors. I've checked the structure you provided with working script configuration and it is errors free (having empty strings for menu items is not the best idea though) so it's not condition 3. Variable names seem to be identical so it?s also not condition 1. So what's left is condition 2 - check if file is on the server, linked properly and can be accessed by the browser.

Snowman - 12/13/2003 at 03:37 AM

thanks for all the great help ive gotten so far. The only reason i have empty strings is because they sit over the buttons images i have on the site.

Well at least that was the theory.

I created a duplicate of the index.php page and called it index2.html and removed all unrelated html from it and the menu indeed works, so i know im linkin to it properly.

I will have to assume that it doesnt work because of the fact that the page displayed is built using php includes. Its the only explanation i can come up with that could explain it.

Ive been right thru my html and error checked it and apart from missing alt"" tags on images there are no errors.

I must mention that on another oscommerce website i use the menu in the header, but i found that i had to place the javascript in the header include file rather than at the bottom of the page to get it to work in that instance... Ive tried that on this one as well but it made no difference.

Im out of ideas... any further suggestions?

Snowman - 12/13/2003 at 04:04 AM

Ah Found the problem :)

because i had the top level of the menu strings empty it wasnt displaying on the php page.

which is weird cause it worked by itself on the test page i did.

I added text to the top levels of the menu and low and behold there it for some reson it requires text on the top level to work in oscommerce

Thanks for all your help :)

Back to forum: