What I am trying to do
I am trying to access several arrays by passing a parameter to a function that is basically controls a slideshow. The parameter I pass to the function is the nameof a <a href=#" name="rebounding" onclick="nextPlayer(this.name)"></a>. Here is one of the arrays I am trying to access.
var reboundingImgs = ['tyson_chandler.png', 'dwight_howard.png', 'zach_randolph.png', 'omer_asik.png', 'nikola_vucevic.png', 'joakim_noah.png'];
The problem
When I pass the parameter to the function that changes the image and I use the [index]instead of getting the index in the array called reboundingImgs[]I get the letter in the string parameter. e.g. parameter + "Imgs"[index] would be "b" if index was 2 and the parameter I pass in is "rebounding". I need to access the arrays using the parameter I pass in to show the right image from the right array( I have several arrays containing images e.g. scoringImgs[], reboundingImgs[], assistsImgs[], etc)
Here is my code
function nextPlayer(typeStatStr) {
var numImgs = 6;
var img = document.getElementById("slideImage");
var imageName = img.name.split("_");
var index = imageName[1];
if (index == numImgs -1) {
return;
}
else {
index++;
}
img.src = "..\\nbaart\\" + typeStatStr + "Imgs"[index];
img.name = "image_" + index;
}
function prevPlayer(typeStatStr) {
var img = document.getElementById("slideImage");
var imageName = img.name.split("_");
var index = imageName[1];
if (index == 0) {
return;
}
else {
index--;
}
img.src = "..\\nbaart\\" + typeStatStr + "Imgs"[index];
img.name = "image_" + index;
}
<head>I do it like this so the browser can pre load them into memory.