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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set Default Value in Javascript

Thread ID:

Created:

Updated:

Platform:

Replies:

117668 Nov 25,2014 08:16 PM UTC Dec 17,2014 10:24 AM UTC ASP.NET MVC 4
loading
Tags: DropDownList
Fabio Melendez
Asked On November 25, 2014 08:16 PM UTC

I have a dropdownlist loaded vith values

@Html.EJ().DropDownList("perSelect").Datasource(Model.Roles).DropDownListFields(per => per.Text("PermissionName").Value("PermissionsId")).EnableIncrementalSearch(true).ShowRoundedCorner(true)


My List has

Name: Admin ID: 1

Name: User ID: 2

So when the application user clicks on a grid to edit the permissions for a user I want to default the value in the dialog that comes up

Trying to do something like this

var dropDown = $("#perSelect").ejDropDownList("instance");

dropDown.data("ejDropDownList").selectItemByValue(record.Role);


But that doesn't work, how would I go about selecting an element from within the dropdown for an edit type functionality



Balamurugan P [Syncfusion]
Replied On November 26, 2014 01:40 PM UTC

Hi Fabio Melendez.

Thanks for using Syncfusion Products. In your code snippet, dropdown list object has been created using $("#perSelect").ejDropDownList("instance") this method, so there is no necessary to use “data (‘ejDropDownList’)” method again. You can achieve your requirement using below code snippet.

Code snippet [JavaScript]:

//create object for ejDropDownList

var dropDown = $("#perSelect").ejDropDownList("instance");

//using ejDropDownList object, we can call selectItemByValue() method

dropDown.selectItemByValue(record.Role);

 

Note: Above code snippet contains “selectItemByValue()“ method. But this method selectItemByValue() name has been changed  as setSelectedValue() in (12.2.0.1) release onwards. So If you are going to use latest version (12.3.0.36) of Essential studio, you need to use “setSelectedValue()” method instead of selectItemByValue()”, then only it will not throw any exception.

 In (12.2.0.1) release, we have made major changes on API to provide consistent API across all our controls and you can find the API changes from the following link / release notes.

http://help.syncfusion.com/ug/js/default.htm#!documents/apichangesdetails.htm

Our latest version of essential studio is available for download under the following link

http://www.syncfusion.com/forums/117495/essential-studio-2014-volume-3-final-release-v12-3-0-36-available-for-download

You can refer the following common user guide for JavaScript/ASP.NET MVC to know more about getting started with our components. Under each components we have provided “Concepts and features” section which explains about the features of the particular component.

http://help.syncfusion.com/web

You can also refer the following class reference link for JavaScript. Since, our ASP.NET MVC components are created as wrapper for the JavaScript components the properties, methods and events will be same for MVC components.

http://help.syncfusion.com/cr/js

Please let us know if you have any queries.

Regards,

Balamurugan P

 

 

 


Fabio Melendez
Replied On December 16, 2014 09:28 PM UTC

How do I unselect the selected item ?

Fabio Melendez
Replied On December 16, 2014 09:43 PM UTC

The problem I have with this is that after the user selects an item from the dropdown list they can not unselect it, so is there a way to unselect a value?

It appears that the blank field shows up initially, but after the value is selected it will not show anymore.

Manikandan Mariappan [Syncfusion]
Replied On December 17, 2014 10:24 AM UTC

Hi Fabio Melendez,

We have analyzed your requirement I have with this is that after the user selects an item from the dropdown list they cannot unselect it, so is there a way to unselect a value?” We have provided following three methods to unselect the value in dropdownlist control.

1. unselectItemByIndex(indexvalue)

2. unselectItemByText(textvalue)

3. unselectItemByValue(value)

In the following code snippet, we have showcased how to unselect the value in dropdownlist using “unselectItemByValue” method.

 

<script>

    var dropObj;

    $(function () {

        dropObj = $("#bikeList").ejDropDownList('instance');

        //we have three way to unselect the selected value in dropdownlist control

        //unselectItemByText,unselectItemByIndex and unselectItemByValue       

        //we follow the followin script section to use the unselectItemByValue

 

        //un select the value by button click event

        $("#click").click(function () {

            dropObj.unselectItemByValue("Dazzler");

        });

    });

</script>

 

 

We have prepared a simple sample to exhibit this behavior, please find the sample from the following location

Sample Location:  Sample

Please let us know if you have further queries,

Regards

Manikandan Mariappan


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.

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

;