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

Previously selected value in dropdown list

Thread ID:

Created:

Updated:

Platform:

Replies:

142758 Feb 18,2019 02:25 PM UTC Feb 21,2019 11:11 AM UTC ASP.NET Core 3
loading
Tags: DropDownList
Petra Visic
Asked On February 18, 2019 02:25 PM UTC

Hello,
is it possible to somehow get the previously selected value in dropdown list on change event? 
I have a dropdown list with several possible options to choose from. On change event, if the previously selected value was 1, I have to reset some fields on form; otherwise, I do not have to reset those fields. Currently I do not see the way to achieve this with Syncfusion's control. 

Prince Oliver [Syncfusion]
Replied On February 19, 2019 08:42 AM UTC

Hi Petra, 
 
Thank you for contacting Syncfusion support.  
 
We have checked your requirement to get previously selected values through change event of DropDownList,  currently we cannot get previous value in change event. However, we can achieve your requirement in the following ways.  
 
  • Method 1:
Bind click event for DropDownList container and store the DropDownList value through this event using a global variable. This variable can be accessed in change event of DropDownList after value changes as shown below. 
 
<ej-drop-down-list id="bikeList" datasource="(IEnumerable<Bikes>)ViewBag.datasource" watermark-text="Select a bike" width="100%" change="onValueChange" > 
        <e-drop-down-list-fields  text="text" value="value" /> 
    </ej-drop-down-list> 
 
  <script> 
        var ddlObj,PreviousVal; 
        $(function () { 
            
            $("#bikeList_container").on("click", function () { 
                ddlObj = $("#bikeList").data("ejDropDownList"); 
                PreviousVal = ddlObj.value(); 
            }); 
 
        }); 
        function onValueChange(args) { 
            if (PreviousVal == 1) { 
                alert("Previous Value before change:" + PreviousVal); 
                //reset the required form fields here if the value is 1. 
            } 
 
        } 
 
    </script> 
 
 
 
  • Method 2:
If you are setting value dynamically without interaction with the component, then you can declare a global variable and assign the value through create event of DropDownList initially. Later this value can be updated through change event of DropDownList for each value change.  
 
<form id="form1"> 
    <ej-drop-down-list id="bikeList" datasource="(IEnumerable<Bikes>)ViewBag.datasource" watermark-text="Select a bike" width="100%" change="onValueChange" create="onCreate"> 
        <e-drop-down-list-fields  text="text" value="value" /> 
    </ej-drop-down-list> 
    <button id="set" onclick="setValue()" type="button">Set Value dynamically </button> 
   
</form> 
    <script> 
        var ddlObj,PreviousVal; 
        function setValue() { 
            ddlObj = $("#bikeList").data("ejDropDownList"); 
            ddlObj.setModel({ value: "1" }); 
        } 
        function onCreate(args) { 
 
            PreviousVal = this.value(); 
        } 
       
        function onValueChange(args) { 
            if (PreviousVal == 1) { 
                alert("Previous Value before change:" + PreviousVal); 
                    //reset the required form fields here if the value is 1 
            } 
            PreviousVal = this.value(); 
 
        } 
 
    </script> 
 
 
You can use any one of the above methods based on your convenience. We have attached a sample for your reference, please find the sample at the following location: http://www.syncfusion.com/downloads/support/forum/142758/ze/PreviousSelectedValue-268518768  
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Prince 


Petra Visic
Replied On February 19, 2019 08:52 AM UTC

Thanks! I am familiar with the method similar to what you have described, I just hoped that your dropdown list control had built-in member for that...

Prince Oliver [Syncfusion]
Replied On February 21, 2019 11:11 AM UTC

Hi Petra, 

Thank you for the update. 

The previously suggested solution will work fine in all cases and we kindly request you to use the same in your end to achieve your requirement. 

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

;