I am working on an educational tool. I want to retrieve a value from one of a group of arrays based on a parameter passed to a function. Specifically, this goal of this code is to change the label text on a group of radio-buttons based on selections by a user.
Here's my code:
//arrays
var bodyplan = ['Anguilliform', 'Compressiform', 'Depressiform', 'Filiform', 'Fusiform', 'Globiform', 'Sagittiform', 'Taeniform']
var caudalshape = ['Continuous', 'Emarginate', 'Forked', 'Lunate', 'Rounded', 'Truncate']
var mouthposition = ["Inferior", "Jawless", "Subterminal", "Superior", "Terminal"]
//function
function changelabels(opt1, opt2){
var i = opt2
var c = 1
var index = 0
while (i>=c){
document.getElementById("rb" + c + "lbl").innerHTML = (opt1[index])
c = c + 1
index = index + 1}}
The call to the function is made in a switch statement that is quite lengthy. For example here is one of the calls:
case 4:
changelabels("caudalshape", 6)
The code I created above does change the labels, but not in the desired way. For the above case instead of my radio-buttons being labeled "Continuous", "Emarginate", "Forked" and so on, they are labeled "c", "a", "u", "d" and so on. In other words the function I wrote is not pulling values from the array. It is simply selecting letters from the parameter word passed tot he function according to the index.
Any help would be appreciated. I'm a relative novice at Javascript. I've been trying to tackle this problem for several hours both in playing with code and in searching these forums.