Take data from an array and apply each array item to an element

I’m trying to grab values from a set of arrays based on the value returned by my select box.

Caveat - this is not an area I have any real experience with

My arrays look like:


/*
var fees_# = ["tuition", "fees", "total"];
*/
var fees_1 = ["38,200", "2,350", "40,550"];
var fees_2 = ["19,750", "2,350", "22,100"];
var fees_3 = ["38,700", "2,450", "41,150"];
var fees_4 = ["19,450", "1,900", "21,350"];
var fees_5 = ["30,000", "5,100", "35,100"];
//and so on

My select will be returning values like:
degree_1a
degree_2a
degree_3a
degree_4a

degree_1b
degree_2b
degree_3b
degree_4b

degree_1c
degree_2c
degree_3c
degree_4c
/…
degree_1z
degree_2z
degree_3z
degree_4z

degree_1aa
degree_2aa
degree_3aa
degree_4aa
/…etc

I then need to test for each, then associate with one of my fees arrays, then grab each of the values in the array and write those values to elements within my page.

I’m then doing this to evaluate for each degree


$(document).ready(function() {
	$('select#degree').change(function(){
		var myValue = $('select#degree').val();
		if(myValue == 'degree_1a'){alert(myValue);}
		if(myValue == 'degree_2a'){alert(myValue);}
		if(myValue == 'degree_3a'){alert(myValue);}
	});
});

I need to first figure out how best to import all of these 60+ arrays and then in each of my conditions pull out each value and write to my page.

There is a unique 1 to 1 relationship between each degree and array so I can’t consolidate as the values for each degree differ slightly.

Any tips/hints/help would be greatly appreciated.

Thanks

I’m not totally clear on what you want, but I’m gonna throw this out there. If I’m wrong, please try to clarify.


var fees = {
    degree_1a: ["38,200", "2,350", "40,550"],
    degree_1b: ["19,750", "2,350", "22,100"]
};

var myValue = "degree_1b";

alert(fees[myValue])

Thank you for responding.

This looks like exactly what I need - I think this will work.

The other thing I need to do is pull each of the array item values out of the selected array and display those values in elements within my page.

if my array breaks down like:

degree = ["tuition", "fees", "total"];

I need to display the respective values like:


<input type="text" name="tuition" value="" readonly="readonly" />
<input type="text" name="fees" value="" readonly="readonly" />
<input type="text" name="total" value="" readonly="readonly" />

If you give each of those form elements a unique id attribute, then you can do something like this for each of them


document.getElementById("tuition").value = fees[myValue][0];