We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Set Value from JS

Thread ID:

Created:

Updated:

Platform:

Replies:

131048 Jun 17,2017 05:02 AM Jun 19,2017 03:18 AM ASP.NET MVC 1
loading
Tags: DropDownList
Ryan Richards
Asked On June 17, 2017 05:02 AM

     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. 

Keerthana Rajendran [Syncfusion]
Replied On June 19, 2017 03:18 AM

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;