- This topic has 2 replies, 3 voices, and was last updated 12 years, 3 months ago by
support-octavio.
-
AuthorPosts
-
Pablo22MemberThis is driving me nuts!
I have a combo box that I populate from a web service that returns a JSON encoded string as follows…function doGetCountries() {
//Clear Country drop down
$(‘#m1-pCheckIn-hidden-select-cCountry’).empty();//Set up AJAX and fill Country drop down
var webURL = “http://www.xxxxxxxx.com/xxxxxxxx/xxxxxxxxx.asmx/GetCountryList”;
$.ajax({
type: “POST”,
url: webURL,
contentType: “application/json”,
dataType: “json”,
success: function(jSON) {
var webJSON = jSON.d;
var webData = webJSON.split(‘;’);
//Parse array into combo
for (var iCount = 2; iCount < webData.length; iCount++) {
$(‘select[name=”cCountry”]’).append( new Option(webData[iCount],webData[iCount]));
}
},
error: function(e){
$(‘#m1-pCheckIn-cTest’).val(‘GetCountryList method failed’);
}
});//End
$(‘select[name=”cCountry”] option[value=”Argentina”]’).attr(‘selected’,’selected’) ;
phoneui.preprocessDOM(‘#m1-pCheckIn’);
return;
}
The combo box populates correctly.
The problem is that no matter what method I use whether it be..
$(‘select[name=”cCountry”] option[value=”Argentina”]’).attr(‘selected’,’selected’) ;
phoneui.preprocessDOM(‘#m1-pCheckIn’);
or
$(‘select[name=”cCountry”]’).val(“Argentina”);
The combo box ALWAYS has the first list value selected (which is Afghanistan) and ‘Argentina’ is in the list.HELP!!!
BrandonMemberJust a thought but if are populating it with the same info each time maybe use something like this:
//select the nth option in list $('select[name="combobox1"] option:eq(2)').attr('selected','selected') phoneui.preprocessDOM('#screenId'); //force UI to update
If the options changes, but the above works, you could also check which index value Argentina is and use that in the code later…
support-octavioMemberHi Pablo,
I did a simple test with your code in a new file with just a combobox and it worked fine. Which make me think about two possible reasons that it is not working for you:
*Your combobox has a different name
*There is no value for a item in the combobox that match with “Argentina” -
AuthorPosts