Set Value from JS

     I just need to set the value of the dropdownlist via JS. I feel like this should be simple but nothing seems to work. A snippet would be great. 

Thanks. 

1 Reply

KR Keerthana Rajendran Syncfusion Team June 19, 2017 07:18 AM UTC

Hi Ryan, 
 
Thank you for contacting Syncfusion support 
 
We can use value property directly in MVC to select an item initially. Please refer to the below code snippet 
 
@Html.EJ().DropDownList("selectCar").TargetID("carsList").ShowCheckbox().EnableRTL(false).Width("150px").Value("Audi A6") 
            <div id="carsList"> 
                <ul> 
                    //Grouping1### 
                    <li>Audi A4</li> 
                    <li>Audi A5</li> 
                    <li>Audi A6</li> 
                    <li>Audi A7</li> 
                    //Grouping2### 
                    <li>Honda H1</li> 
                    <li>Honda H2</li> 
                    <li>Honda H3</li> 
                    <li>Honda H4</li> 
                </ul> 
           </div> 
 
We can also bind value through JS during DropDownList creation as shown below 
 
@Html.EJ().DropDownList("selectCar").TargetID("carsList").ShowCheckbox().EnableRTL(false).Width("150px").ClientSideEvents(e=>e.Create("oncreate")) 
 
<script> 
        function oncreate() 
        { 
            var ddlobj = $("#selectCar").data("ejDropDownList") 
            ddlobj.option({ value: "Audi A7" }); 
        } 
             
    </script> 
 
We have prepared sample for your reference. Please refer to the below given link 
 
 
 
 
 
Regards, 
Keerthana. 


Loader.
Up arrow icon