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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dinamically select item in dropdownlist with javascript

Thread ID:

Created:

Updated:

Platform:

Replies:

143344 Mar 15,2019 02:29 AM UTC Mar 15,2019 12:31 PM UTC JavaScript - EJ 2 1
loading
Tags: DropDownList
Juan José
Asked On March 15, 2019 02:29 AM UTC

Hi, 
I have a page with a dropdownlist element defined like this:
<div class="form-group">
                    @Html.LabelFor(model => model.IdCiudad, htmlAttributes: new { @class = "control-label col-md-4" })
                    @Html.EJS().DropDownListFor(model => model.IdCiudad).DataSource((IEnumerable<Credito.Models.CiudadViewModel>)ViewBag.Ciudades).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "Nombre", Value = "IdCiudad" }).Render()
                    @Html.ValidationMessageFor(model => model.IdCiudad, "", new { @class = "text-danger" })
                </div>

But, I need to select a value and show the correspondent text using javascript.
I am using this: var ddlObj1 = new ej.dropdowns.DropDownList({
                        value: $("#IdCiudad").val()
                    });
                    ddlObj1.appendTo("#IdCiudad"); 
but it creates a second dropdownlist over the one already created. 

How can I get the instance of a syncfusion object? It is not as clear as it is in version (EJ1), and documentation is very poor.
Sorry to express my annoyance but, I feel frustrated
I am consulting this urls for documentation:
https://ej2.syncfusion.com/aspnetmvc/documentation/introduction/
https://ej2.syncfusion.com/javascript/documentation/introduction/
but is not clear, not enough, no samples on that. 
There are others links where I could find documentation?

Regards,

Juan J.



Prince Oliver [Syncfusion]
Replied On March 15, 2019 12:31 PM UTC

Hi Juan, 

Thank you for contacting Syncfusion support. 

Query : I need to select a value and show the correspondent text using javascript.  

You can get or select the value using the value property which is accessible via control’s instance. Kindly refer to the following code snippet. 

// Access the control's instance 
var ddlObj1 = document.getElementById("IdCiudad").ej2_instances[0]; 
 
// Use the value property to select a value 
ddlObj1.value = $("#IdCiudad").val(); 
 
//Call the dataBind method to affect the change immediately 
ddlObj1.dataBind(); 
 
Query : How can I get the instance of a syncfusion object? It is not as clear as it is in version (EJ1), and documentation is very poor. 
 
You can also pass the component as second argument in ‘getComponent()’ method to get the instance. Please refer the below standard way to access the component instance.   
var rbObj = ej.base.getComponent(document.getElementById("rdEmp"), ej.buttons.RadioButton);   
rbObj.checked = true;   
  
We will update our documentation about this standard way to access the component and it will be available in our Essential Studio Volume 1, 2019 release.  

Please let us know if you need any further assistance on this.  

Regards, 
Prince 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon