Please excuse my ignorance on this. I have the code doing what I need, but, I know there is a more elegant solution. It simply evades me and my hours of tinkering and googling.
I have a select box. When the selection changes I get the value and make some changes to some elements. The selected value is an array name - but I do not know how to take $(this).val() and use it to access the matching array, which has forced me to do everything longhand.
<select id="theme">
<option value="cherry">Cherry</option>
<option value="black">Black</option>
<option value="blueberry">Blueberry</option>
<option value="vanilla">Vanilla</option>
</select>
<div id="bgColorTxt">
<span id="hiColorTxt">TEXT</span><span id="loColorTxt">TEXT</span>
</div>
......
$("#theme").change(function() {
var black = [ "000000", "C9C8C9", "3D3A3E" ];
var vanilla = [ "C5C4C1", "ffffff", "9A9998" ];
etc...
if ($(this).val() === "vanilla") {
$('#bgColor').val(vanilla[0]);$('#hiColor').val(vanilla[1]);$('#loColor').val(vanilla[2]);
$('#bgColorTxt,#hiColorTxt,#loColorTxt').css('background-color','#'+vanilla[0]);
$('#hiColorTxt').css('color','#'+vanilla[1]);
$('#loColorTxt').css('color','#'+vanilla[2]);
} else if ($(this).val() === "black") {
I've tried having the names in the select as black[], vanilla[] and tried accessing via $(this).val()[] and all sorts of different ways.
What I would like to do is something like this:
$('#bgColor').val(arrayname[0]);$('#hiColor').val(arrayname[1]);$('#loColor').val(arrayname[2]);
$('#bgColorTxt,#hiColorTxt,#loColorTxt').css('background-color','#'+arrayname[0]);
$('#hiColorTxt').css('color','#'+arrayname[1]);
$('#loColorTxt').css('color','#'+arrayname[2]);
Thanks for any pointers