can't assign values to variables inside change()[SOLVED]
I'm trying to make a number drop list that will control how many drink drop lists there will be.
these are the values I'm trying get, but it doesn't seem to work
var former = $(this).closest('tr.food').next('tr.drink').find('div').length;
var now = $(this).val('quantity');
-
$('select[name="quantity"]').change(function() {
var former = $(this).closest('tr.food').next('tr.drink').find('div').length;
var now = $(this).val('quantity');
if (former < now) {
for (i=former; i < now; i++) {
$(this).closest('tr.food').next('tr.drink').find('div').append('<div><select name="drink"><option value="Cola">Cola</option><option value="Fanta">Fanta</option><option value="Sprite">Sprite</option></select></div>').hide();
}
$(this).closest('tr.food').next('tr.drink').find('div').fadeIn();
}
if (former > now) {
for (i=former; i > now; i--) {
$(this).closest('tr.food').next('tr.drink').find('div:last').remove();
}
}
});
Any solution to this?