I am trying to use AJAX to populate a dropdown list based on the choice of another dropdown list. I followed the tutorial using jQuery located here - http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ and changed the names of the identifiers of the select box in the names of the select boxes in the script .
When changing the value of the main flag, ajax is sent and returned, as shown below:
{"1":"Kieran Hutchinson","2":"Caleb Tan","3":""}
This is slightly different from the JSON string that is returned in the tutorial code, which looks like this:
[{optionValue:10, optionDisplay: 'Remy'}, {optionValue:11, optionDisplay: 'Arif'}, {optionValue:12, optionDisplay: 'JC'}]
I think this is a problem, but I have no idea how to get the correct values from my JSON response.
Javascript is as follows:
$(function(){
$("select#ContactCompanyId").change(function(){
$.getJSON("contactList",{id: $(this).val(), ajax: 'true'}, function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
}
$("select#QuoteContactId").html(options);
})
})
})
Thanks in advance