Click here to Skip to main content
15,921,530 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more:
hi,
I have a dropdown in MVC like
SQL
@Html.DropDownList("CompanyID", null, "Select Company", new { onchange = "GetDiv()" })
 @Html.DropDownList("WarehouseID",null, new { @class = "warehouse-select" })


here on click of first dropdown a javascript function will be called and bind related data to second dropdown.
so, here is my javascript where i used plugin
function GetDiv() {
        debugger;
        var warehouseno = $("#CompanyID").val();
        $.ajax(
        {
            type: "POST",
            url: "@Url.Action("GetWarehouseDropdown", "SearchJDE")",
            dataType: 'json',
            data: { id: warehouseno },
            success: function (result) {
                //$("#WarehouseID").html("");
                for (var i = 0; i < result.length; i++)
                {
                    var item = result[i];
                    $('ul.chzn-results').append('<ul><li class="active-result">' + item.Text + '</li></ul>').css({ "width": "288px" });                    
                }               
            },
            error: function (req, status, error) {
                alert(error);
            }
        });
    }


I am successful in binding data to dropdown but chosen plugin is not working properly.I am not able to see selected value in dropdown, and even search box is also not availabla like single select
http://harvesthq.github.io/chosen/[^]
Please help me.
Posted
Updated 28-Apr-14 21:38pm
v2

1 solution

you need to call that function on

JavaScript
 $(document).ready(function () {
GetDiv();
});


// Need to some changes in function

JavaScript
     $("#CompanyID").empty();
     var listItems = "";
     var jsonData = result;
     listItems = "<option value="">" + "" + "</option>";
     for (var i = 0; i < jsonData.length; i++) 
     {
     listItems += "<option value="" + jsonData[i].ID + "">" + jsonData[i].Value+<option>";
      }                  
      $("#CompanyID").html(listItems);
</option></option>
 
Share this answer
 

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