Hello,
I’ve got a problem thats got me pretty stumped. I’m adapting a menu script (which I’ll be getting the paid version for if this works!) to work with a shopping cart system. The menu script (COOLjsMenu) builds an array with code that looks like this…
[CODE]
var MENU_ITEMS = [
{pos:[10,10], itemoff:[0,99], leveloff:[21,0], style:STYLE, size:[22,100]},
{code:”Item 1″,
sub:[
{code:”SubItem 1″,
sub:[
{code:”SubSubItem 1″},
{code:”SubSubItem 2″},
{code:”SubSubItem 3″}
]
},
{code:”SubItem 2″,
sub:[
{code:”SubSubItem 1″},
{code:”SubSubItem 2″},
{code:”SubSubItem 3″}
]
},
]
},
{code:”Item 2″,
sub:[
{code:”SubItem 1″,
sub:[
{code:”SubSubItem 1″},
{code:”SubSubItem 2″},
{code:”SubSubItem 3″}
]
},
{code:”SubItem 2″,},
{code:”SubItem 3″,
sub:[
{code:”SubSubItem 1″},
]
}
]
},
];
The shopping cart system dumps an array which I’ve written a script for that constructs the code into a string var (called menucode) that has the same formatting as above.
If I cut and paste the output from my code into the script to use then it works no problem, but I need it to take the string I’ve built it into and use that.
The issue is that using “var MENU_ITEMS = menucode” doesn’t make MENU_ITEMS as an array, it just makes another string.
How do I get it so that I can make MENU_ITEMS an array built from the string menucode?
Thanks for any help you can give me on this one guys,
Regards,
Leonard
<i>
</i>menucode = "Home~index.html::Products~products.html::Company~company.html";
var arr = menucode.split("::");
for (var i=o;i<arr.length;i++) {
var tmp = arr[i].split("~");
menucode[i][0] = tmp[0];
menucode[i][1] = tmp[1];
}
//rinse and repeat as many times as you need
<i>
</i>var menucode = "Home~index.html::Products~products.html::Company~company.html";
var MENU_ITEMS = new Array();
var arr = menucode.split("::");
for (var i=o;i<arr.length;i++) {
var tmp = arr[i].split("~");
MENU_ITEMS[i][0] = tmp[0];
MENU_ITEMSe[i][1] = tmp[1];
//you could use more loops here for however deep you want the menu to be
}
[code=php]
<html>
<head>
<title>Menu Array</title>
<script type="text/javascript">
var menucode = "Home~index.html::Products~products.html::Company~company.html";
var menuArray = new Array();
function SplitStr(str) {
var arr = str.split("::");
for (var i=0;i<arr.length;i++) {
var tmp = arr[i].split("~");
menuArray[i][0] = tmp[0];
menuArray[i][1] = tmp[1];
}
}
//rinse and repeat as many times as you need
function ShowArray() {
var str = '';
for (var i=0;i<menuArray.length;i++) {
str += menuArray[i][0];
str += 'n'+menuArray[i][1];
}
alert(str);
}
</script>
</head>
<body>
<button onClick="SplitStr(menucode)">Split String</button><br />
<button onClick="ShowArray()">Show Array</button><br />
</body>
</html>
[/code]
<i>
</i>var menucode = "Home~index.html::Products~products.html::Company~company.html";
var menuArray = new Array();
var arr = menucode.split("::");
for (var i=0;i<arr.length;i++) {
menuArray[i] = new Array();
<i> </i>var tmp = arr[i].split("~");
<i> </i>menuArray[i][0] = tmp[0];
<i> </i>menuArray[i][1] = tmp[1];
}
alert(menuArray[1][1])
var str = '';
for (var i=0;i<menuArray.length;i++) {
str += menuArray[i][0];
str += ' = '+menuArray[i][1]+ "n";
}
alert(str);
After taking a look at it, it seems like you have initialize each instance of the second dimension of the array individually. [/QUOTE]
Can you post an example the string "menucode"?[/QUOTE]
[CODE][ {pos:[10,10], itemoff:[21,0], leveloff:[0,99], style:STYLE, size:[22,100]},{code:"Amplification", "url":"/cgi_data/ss000001.pl?SECTIONID=Amplification%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Trace Elliot", "url":"/cgi_data/ss000001.pl?SECTIONID=Trace%5fElliot%5fBass%5fAmps%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%5fBass%5fAmp%2ehtml&NOLOGIN=1"},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fbass%5famps%2ehtml&NOLOGIN=1"},],},{code:"Acoustic Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%5fAcoustic%2ehtml&NOLOGIN=1"},],},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%5fGuitar%5fAmplifiers%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fguitar%5famps%2ehtml&NOLOGIN=1"},{code:"Vox", "url":"/cgi_data/ss000001.pl?SECTIONID=Vox%5fguitar%5famps%2ehtml&NOLOGIN=1"},],},],},{code:"Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Guitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%2ehtml&NOLOGIN=1",sub:[{},{code:"12-String Acoustics", "url":"/cgi_data/ss000001.pl?SECTIONID=12%2dString%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Beginners Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Beginners%5fAcoustic%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fAcoustic%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Left-Handed", "url":"/cgi_data/ss000001.pl?SECTIONID=Left%2dHanded%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Washburn", "url":"/cgi_data/ss000001.pl?SECTIONID=Washburn%5facoustic%5fguitars%2ehtml&NOLOGIN=1"},],},{code:"Bass Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fBass%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fStarter%5fPacks%2ehtml&NOLOGIN=1"},],},{code:"Classical", "url":"/cgi_data/ss000001.pl?SECTIONID=Classical%2ehtml&NOLOGIN=1",sub:[{},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fclassicals%2ehtml&NOLOGIN=1"},],},{code:"Electric", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%2ehtml&NOLOGIN=1",sub:[{},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fPacks%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=dean%5felectrics%2ehtml&NOLOGIN=1"},{code:"ESP Ltd.", "url":"/cgi_data/ss000001.pl?SECTIONID=ESP%5fLtd%5fEL%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%2ehtml&NOLOGIN=1"},{code:"Lag", "url":"/cgi_data/ss000001.pl?SECTIONID=Lag%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectric%5fGuitars%2ehtml&NOLOGIN=1"},],},],},{code:"Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Effects%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{},],},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{},{code:"Multi-Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fMulti%5fEffects%2ehtml&NOLOGIN=1"},{code:"Stomp Boxes", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fStomp%5fBoxes%2ehtml&NOLOGIN=1"},],},],},{code:"Drums", "url":"/cgi_data/ss000001.pl?SECTIONID=Drum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Electronic Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Electronic%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectronic%5fKits%2ehtml&NOLOGIN=1"},],},{code:"Starter Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Ludwig", "url":"/cgi_data/ss000001.pl?SECTIONID=Ludwig%5fDrum%5fKits%2ehtml&NOLOGIN=1"},],},],},{code:"Audio Software", "url":"/cgi_data/ss000001.pl?SECTIONID=Audio%5fSoftware%2ehtml&NOLOGIN=1",sub:[{},{code:"IK Multimedia", "url":"/cgi_data/ss000001.pl?SECTIONID=IK%5fMultimedia%2ehtml&NOLOGIN=1",sub:[{},],},],},]; [/CODE]
Leonard_B:
Thanks for the original post.[/QUOTE]
[CODE]var MENU_ITEMS = [ {pos:[10,10], itemoff:[21,0], leveloff:[0,99], style:STYLE, size:[22,100]},{code:"Amplification", "url":"/cgi_data/ss000001.pl?SECTIONID=Amplification%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Trace Elliot", "url":"/cgi_data/ss000001.pl?SECTIONID=Trace%5fElliot%5fBass%5fAmps%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%5fBass%5fAmp%2ehtml&NOLOGIN=1"},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fbass%5famps%2ehtml&NOLOGIN=1"}]},{code:"Acoustic Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Mark Bass", "url":"/cgi_data/ss000001.pl?SECTIONID=Mark%5fBass%5fAcoustic%2ehtml&NOLOGIN=1"}]},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fAmps%2ehtml&NOLOGIN=1",sub:[{},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%5fGuitar%5fAmplifiers%2ehtml&NOLOGIN=1"},{code:"Line 6", "url":"/cgi_data/ss000001.pl?SECTIONID=Line%5f6%2ehtml&NOLOGIN=1"},{code:"Roland", "url":"/cgi_data/ss000001.pl?SECTIONID=Roland%5fguitar%5famps%2ehtml&NOLOGIN=1"},{code:"Vox", "url":"/cgi_data/ss000001.pl?SECTIONID=Vox%5fguitar%5famps%2ehtml&NOLOGIN=1"}]}]},{code:"Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Guitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Acoustic%2ehtml&NOLOGIN=1",sub:[{},{code:"12-String Acoustics", "url":"/cgi_data/ss000001.pl?SECTIONID=12%2dString%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Beginners Acoustic", "url":"/cgi_data/ss000001.pl?SECTIONID=Beginners%5fAcoustic%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fAcoustic%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Left-Handed", "url":"/cgi_data/ss000001.pl?SECTIONID=Left%2dHanded%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fAcoustics%2ehtml&NOLOGIN=1"},{code:"Washburn", "url":"/cgi_data/ss000001.pl?SECTIONID=Washburn%5facoustic%5fguitars%2ehtml&NOLOGIN=1"}]},{code:"Bass Guitars", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitars%2ehtml&NOLOGIN=1",sub:[{},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5fBass%5fGuitars%2ehtml&NOLOGIN=1"},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fStarter%5fPacks%2ehtml&NOLOGIN=1"}]},{code:"Classical", "url":"/cgi_data/ss000001.pl?SECTIONID=Classical%2ehtml&NOLOGIN=1",sub:[{},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=Dean%5fclassicals%2ehtml&NOLOGIN=1"}]},{code:"Electric", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%2ehtml&NOLOGIN=1",sub:[{},{code:"Starter Packs", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fPacks%2ehtml&NOLOGIN=1"},{code:"Dean", "url":"/cgi_data/ss000001.pl?SECTIONID=dean%5felectrics%2ehtml&NOLOGIN=1"},{code:"ESP Ltd.", "url":"/cgi_data/ss000001.pl?SECTIONID=ESP%5fLtd%5fEL%2ehtml&NOLOGIN=1"},{code:"Guvnor", "url":"/cgi_data/ss000001.pl?SECTIONID=Guvnor%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Peavey", "url":"/cgi_data/ss000001.pl?SECTIONID=Peavey%2ehtml&NOLOGIN=1"},{code:"Lag", "url":"/cgi_data/ss000001.pl?SECTIONID=Lag%5felectric%5fguitars%2ehtml&NOLOGIN=1"},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectric%5fGuitars%2ehtml&NOLOGIN=1"}]}]},{code:"Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Effects%2ehtml&NOLOGIN=1",sub:[{},{code:"Bass Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Bass%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{}]},{code:"Electric Guitar", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fEffects%2ehtml&NOLOGIN=1",sub:[{},{code:"Multi-Effects", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fMulti%5fEffects%2ehtml&NOLOGIN=1"},{code:"Stomp Boxes", "url":"/cgi_data/ss000001.pl?SECTIONID=Electric%5fGuitar%5fStomp%5fBoxes%2ehtml&NOLOGIN=1"}]}]},{code:"Drums", "url":"/cgi_data/ss000001.pl?SECTIONID=Drum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Electronic Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Electronic%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Yamaha", "url":"/cgi_data/ss000001.pl?SECTIONID=Yamaha%5fElectronic%5fKits%2ehtml&NOLOGIN=1"}]},{code:"Starter Kits", "url":"/cgi_data/ss000001.pl?SECTIONID=Starter%5fDrum%5fKits%2ehtml&NOLOGIN=1",sub:[{},{code:"Ludwig", "url":"/cgi_data/ss000001.pl?SECTIONID=Ludwig%5fDrum%5fKits%2ehtml&NOLOGIN=1"}]}]},{code:"Audio Software", "url":"/cgi_data/ss000001.pl?SECTIONID=Audio%5fSoftware%2ehtml&NOLOGIN=1",sub:[{},{code:"IK Multimedia", "url":"/cgi_data/ss000001.pl?SECTIONID=IK%5fMultimedia%2ehtml&NOLOGIN=1",sub:[{}]}]}][/CODE]
[CODE]menucode = '[ {pos:[10,10], itemoff:[21,0], leveloff:[0,99], style:STYLE, size:[22,100]},{code:"Am...' etc
var MENU_ITEMS = menucode ;[/CODE]
<i>
</i>var menucode = {
name : "Home",
pos : [10,10],
url : "http://whaterver.com"
}
alert(menucode.name) //"Home"
alert(menucode['pos']) //"Array"
alert(menucode['pos'][0]) //Should alert "10" i think
alert(menucode[2]) //"http://whatever.com"
0.1.9 — BETA 4.29