I have the following JavaScript/jQuery problem:
- Combobox is populated on the client side by calling a web service
- Select an item in the combobox after it is populated
I can't post the entire code, but tried to snip out the interesting parts:
HTML:
<select name="RegionId">
</select>
JavaScript:
$(function () {
$.getJSON('/hotels/GetRegionsByCountry/1', function (data) {
var items = [];
$.each(data, function (index) {
items.push('<option value="' + this.Id + '">' + this.Name + '</option>');
});
$("[name='RegionId']").html(items.join(''));
});
$("[name='RegionId']").val("24");
});
Problem: After the combobox is populated (1) the selection fails (2).
It seems to me that jQuery can't access the items that were populated. But why?