Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
function changePlant() {
$("#ShopID").empty();
var selectedPlantName=$("#Plantid").val();
$.ajax({
url: "/User/getShopList?abc="+selectedPlantName,
success: function (data1) {

// alert(data1);
$("#ShopID").append("<option>" + data1 + "</option>");
}


});
}
but it shows shop1,shop2 in dropdownlist at one tme i want to show like firstly shop1 then sencond row shop2..plz help me?
Posted
Updated 5-Mar-14 0:17am
v2

1 solution

Well, from what I understand data1 is a comma separated list of values.

So you have to split[^] it on the comma (you'll end up with an array) and add the options to the list.

JavaScript
function (data1) {
    //data1 contains shop1,shop2
    var items = data1.split(',');
    
    var jSelect = $("#ShopID"); // Just store this in a variable, so the loop doesn't have to do the lookup every time.
    for (var i = 0, len = items.length; i < len; ++i) {
        jSelect.append('<option>' + items[i] + '</option>');
    }
}
 
Share this answer
 
v2
Comments
Member 9027346 5-Mar-14 6:39am    
i used split function but if i used that time data not shown??
Maarten Kools 5-Mar-14 6:45am    
I don't know what the web service returns, from your initial post I gathered it's a comma separated string. I suggest you look carefully at what the server is returning, and act accordingly. If you need the help, please post what exactly is returned and then I (or someone else) can help you better.
Member 9027346 5-Mar-14 6:48am    
it returns shop1,shop2.
Maarten Kools 5-Mar-14 6:51am    
I've added a little code snippet in my solution
Member 9027346 5-Mar-14 22:16pm    
i used above but still not working actually split and append intellesens not showing???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900