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. Image for the cookie policy date

Assign value from dropdownlist on change

I have a dropdownlist which contains value, text and estimatedHours, how can I estimatedHours  to another input field on change?

<ej-drop-down-list id="serviceList"
                        ej-for="@Model.Trade.Service_Fk"
                        datasource="(IEnumerable<ServiceItem>)@Model.Services"
                        watermark-text="Select a service"
                        width="250px"
                        change="serviceList_change"
                        value="@Model.Trade.Service_Fk"
                        template="<div> ${text} </div> <div class='estHrs'>${estimatedHours} </div>">
                        <e-drop-down-list-fields text="text" estimatedHours="estimatedHours"/>
</ej-drop-down-list>

<ej-numeric-text-box id="EstimatedHours" decimal-places="1" ej-for="@Model.Trade.EstimatedHours" increment-step=".5" />

<script>
         function serviceList_change(args) {

             var dropdownObj = $("#serviceList").ejDropDownList('instance');

             ??????????????????????

         }
    </script>

1 Reply

PO Prince Oliver Syncfusion Team May 29, 2017 07:09 AM UTC

Hi Karen,   
  
Thank you for contacting Syncfusion support.   
  
To set ‘estimatedHours’ field in dropdownlist datasource to another input field on change event, we need to get the ‘estimatedHours’ field based on the selected text value from the dropdownlist and then set it to numeric textbox. Kindly refer to the following code snippet.   

<script> 
    function serviceList_change(args) { 
        var dropdownObj = $("#serviceList").ejDropDownList('instance'); 
        var numericObj = $("#EstimatedHours").data("ejNumericTextbox"); 
        var selectedhour; 
        for(i = 0; i < dropdownObj.model.dataSource.length; i++) {  
            if (dropdownObj.model.dataSource[i].text == args.selectedText) {  
                selectedhour = dropdownObj.model.dataSource[i].EstimatedHours 
            } 
        } 
        numericObj.setModel({ value: selectedhour }); 
    } 
</script> 


Regards, 
Prince 


Loader.
Up arrow icon