Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
constructing array name
Alex DeLaad
Greenhorn
Posts: 3
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi,
i have a few arrays called
menu1, menu2, menu3 etc.......
In a function I wish to create the array name by a variable passed in, so that i can dynamically create the array name.
menu1 = new Array( "Link1", "link1.htm"); menu2 = new Array( "Link2", "link2.htm"); menu3 = new Array( "Link3", "link3.htm"); .. .. .. function createarrayname(index) { arrayName= 'menu' + index; oneString = "<a href='" + arrayName[1] + "'>" + arrayName[0] + "</a>"; return oneString; }
If anyone could help please
Eric Pascarello
author
Posts: 15385
6
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
use a multideminsional array instead
var Menu = new Array()
Menu[1] = new Array()
Menu[2] = new Array()
James Swan
Ranch Hand
Posts: 403
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Or you can use "eval" and do something like this:
<html> <head> <script language="JavaScript"> var menu1 = new Array("Link1","link1.htm"); var menu2 = new Array("Link2","link2.htm"); var menu3 = new Array("Link3","link3.htm"); function createarrayname(index) { var oneString = "<a href='" + e-val("menu" + index + "[1]") + "'>" + e-val("menu" + index + "[0]") + "</a>"; alert(oneString); } </script> </head> <body> <form> <input type="button" value="click me" on-Click="createarrayname(1);createarrayname(2);createarrayname(3);"> </form> </body> </html>
Note: change "e-val" to "eval" and "on-Click" to "onClick"
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Generating Horizontal Menu in JSF using h:dataTable
browser back button problem.
i need space between menus
howto make html:link dynamic select item of map ?
how to iterate list in a table using jstl
More...