i Want write public function for Fill DropDownlist. and when programer want fill DropDownlist Call this method and set parametrs. i write this code
function FillDropDownlist(url,dataPas,selector,indexValue,indexText) {
$.ajax({
cache: false,
contentType: 'application/json; charset=utf-8',
url: url,
data:{dataPas},
success: function (data) {
var rows = data.rows;
var drpTransportType = $(selector);
var strOption = '<option value=0>...Select.....</option>';
$(selector+" option").remove();
if (data.rows.length >= 0) {
for (var i = 0, l = rows.length; i < l; i++) {
var ri = rows[i];
strOption += '<option value="' + ri.cell[indexValue] + '">' + ri.cell[indexText] + '</option>';
}
drpTransportType.append(strOption);
}
},
dataType: 'json'
});
}
and for call i write this code
FillDropDownlist("JQGridHandler.ashx", "ActionPage:'TransportType',Action:'FillDrop'", "#Select1", 0, 1);
but this code not work, and get Error
Error: FillDropDownlist is not defined
i think this line have error
data:{dataPas},
please help me for complete this function, thanks all
Couple of things: (1) use camelCase naming convention for JavaScript function names. (2) Make sure the function is evaluated before you call it. So if it’s in a different js file, make sure that is included before the one that calls the function. (3) Change
data:{dataPas}todata: dataPas(I think you misspelled “pass” but anyway). Then yourdataPasobject should be in javascript object notation likedataPas = {foo: "foo", bar: "bar"};