Hi Guys,
Im tyring to use AJAX to populate a dropdown box based on the selection of another dropdown. I followed a tutorial using jQuery located here - http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ and have altered the select box ID names in the select box names in the script.
When a chagne the value of the main checkbox the ajax is sent and returns as below:
{"1":"Kieran Hutchinson","2":"Caleb Tan","3":""}
THis is slightly different to the JSON string that is returned in the tutorials code which looks like this
[{optionValue:10, optionDisplay: 'Remy'}, {optionValue:11, optionDisplay: 'Arif'}, {optionValue:12, optionDisplay: 'JC'}]
Im thinking this is the issue but i have no idea how to get the correct values out of my JSON response.
The javascript is as below:
$(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