I have a snippet of code which I want to use to display a certain description in the div #selectedRadio.
However, instead of showing the variable value (e.g. "Example description 1"), it is showing the variable name (e.g. "desc1").
var desc1 = 'Example description1';
var desc2 = 'Example description2';
$('input[name="expenseCat"]').change(function() {
for (var i = 1; i <= 2; i++) {
if (this.value == i) {
$('#selectedRadio').text(['desc'+i]);
}
}
});
If I use this instead, it works fine (but obviously it's not dynamic, and so it's basically useless):
$('#selectedRadio').text(desc1);
What am I doing wrong? How can I get it to display the value of the variable instead of its name?
Thanks in advance!