HTML:
<select id="staylength" name="staylength">
<option disabled="disabled" value="1">1</option>
<option disabled="disabled" value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
In Google Chrome (5.0.375.55 on WinXP), the following jquery code fails to set the value of staylength.
var my_min = 3;
$('#staylength').val(my_min);
But the same, when run from javascript console in Google Chrome, is successful. What Is wrong?
Edit
Here is the offending page:
http://dv2.makestay.com/node/1
To reproduce the error select either ’06/21/2010′ or ’06/22/2010′ as Check-In Date. The value failing to get updated is in Nights select.
EDIT 2
This is the whole function. It is called with parameter set to 3:
function apply_restriction(i) {
var my_index = parseInt(i);
var my_option;
var my_min = min_stay[my_index];
$('#staylength').html('');
for (var j=1; j < 15; j++) {
if (parseInt(j) < parseInt(my_min)) {
my_option = '<option value="' + j + '" disabled="disabled">' + j + '</option>';
} else {
my_option = '<option value="' + j + '">' + j + '</option>';
}
$('#staylength').append(my_option);
}
$('#staylength').val('' + my_min);
alert($('#staylength').length);
}
Updated
The issue is this line:
min_stayis an array of strings, so this is resulting in “31”, not4like you want (and “31” is outside the values in the list, resulting it it defaulting back to the first<option>), you either need to return an array of integers in your response, instead of this:or, use
parseInt()like this: