/    Sign up×
Community /Pin to ProfileBookmark

I see the problem, is there an answer?

In the following script, I want to select from the various ‘indxA’ … ‘indxJ’ arrays.
But the way I have coded it, it thinks ‘myindx’ is a string and is passing back the characters of the string instead of the elements of the selected array.

Is there a way to code this differently so that it works the way I want?

[code=php]
<html>
<head>
<title>Indirect Loop</title>
<script type=”text/javascript”>
var indxA = new Array(‘A’,”Abner”,”Allison”,”Avery”);
var indxB = new Array(‘B’,”Barney”,”Beenie”,”Beers”,”Boop”);
var indxC = new Array(‘C’,”Cary”,”Connelly”,”Conroy”,”Crestview”,”Custer”);
var indxD = new Array(‘D’,’Duck’);
var indxE = new Array(‘E’,’Elliot’,’Emory’,’Excellent’);
var indxF = new Array(‘F’,’Fudd’);
var indxG = new Array(‘G’);
var indxH = new Array(‘H’);
var indxI = new Array(‘I’);
var indxJ = new Array(‘J’);

function Act(info) {
var strmsg = ”;
myindx = ‘indx’+info;
for(var i=0; i<myindx.length; i++) {
strmsg+=”<a href=’#null’>”+myindx[i]+'</a> ‘; // strmsg+=”<br>”; // for vertical display
}
document.getElementById(“divdis”).innerHTML=strmsg;
}
AlphaIndex = {
Chrs : new Array(‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’),
// ,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’),

InitH : function() {
document.writeln(‘<table border=”0″><tr>’);
for (az=0; az<this.Chrs.length; az++) {
document.writeln(‘<td><button onClick=”Act(”+this.Chrs[az]+”)”>’+this.Chrs[az]+'</button>’);
}
document.writeln(‘</tr></table>’);
}
}
</script>
</head>
<body>
<script type=”text/javascript”> AlphaIndex.InitH(); </script>
<br>
<div id=divdis ></div>
</body>
</html>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@felgallMar 21.2007 — replace:

myindx = 'indx'+info;

with

myindx = window['indx'+info];
Copy linkTweet thisAlerts:
@JMRKERauthorMar 21.2007 — Perfect 'fengall'. Thanks a bunch.

I have not seen this syntax before.
×

Success!

Help @JMRKER 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 4.29,
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,
)...