My dropdown values are showing alphabetical order. But i dont need like that. Because when I add values it is changing the alphabetical order.
For Example,
I have number of functions
-
— Designer– // Subfunction
-
Accessory Designer
..so on.
But My dropdown showing
-
Accessory Desinger,
-
–Desinger–.
My Jquery code here
$('#dropdown').change(function () {
$("#dropdown1").show();
$.ajax({
url: "/Jobs/dropdown1",
type: 'GET',
data: { 'dropdownId': $(this).val() },
dataType: 'json',
success: function (response) {
if (response.Success) {
$('#dropdown1').children().remove();
$.each(response.dropdown1, dropdown (index, role) {
$('#dropdown1').append(
'<option value="' + dropdown1.Id + '">' +
dropdown1.Name +
'</option>');
});
}
},
error: function (xhr, status, error) {
}
});
});
when I click first dropdown, It is automatically show the second Dropdown.
Please help me out of this problem.
If you don’t know how to change the order on the server side, you must do it in the client.
From your description I gather the result is a
JSONobject with each item havingIdandName, and that you want to iterate them not by name, but by id.Therefore I suggest the following change to your code:
That should sort the resultset by
Idbefore the items are added to#Roles.