-3

#date is a select tag (dropdown menu).

I already have a variable date001 and I want to change its value according to new value of dropdown menu.

$("#date").change(function() {
    var a = $("#room").html();  // result is `001` - it's ok
    var $("date" + a) = $(this).val(); // doesn't work !
});
qadenza
  • 9,025
  • 18
  • 73
  • 126

1 Answers1

2

$("date" + a) is a jQuery selector; it's not doing what you think it's doing.

What's more likely is doing something like this:

window['date' + a] = $(this).val();

This isn't good practice, so perhaps you should attach your date001 variable, and others like it, to an object and reference them that way.

myObj['date' + a] = $(this).val();
chazsolo
  • 7,873
  • 1
  • 20
  • 44