Copy ListBox items to Multilne TextBox

Hi,

I have a ListBox with some items on my page. I want to be copy a selected item from the ListBox to a multiline TextBox when I double click on the item.


If this is possible, please share the code with me.


3 Replies 1 reply marked as answer

YA YuvanShankar Arunagiri Syncfusion Team June 24, 2022 07:59 AM UTC

Hi Eddie,


We have validated your reported query and prepared the sample based on your requirement. We can achieve your requirement by using value property of the listbox and textbox.

[Index.cshtml]:

@using Syncfusion.EJ2.Inputs

@using Syncfusion.EJ2.DropDowns

 

<div id="listbox-control">

    @Html.EJS().ListBox("listbox").DataSource((IEnumerable<object>)ViewBag.data).Render()

</div>

 

<div class="multiline_wrapper">

    @Html.EJS().TextBox("default").Multiline(true).Placeholder("Listbox Data").Created("OnCreated").Render()

</div>

 

<script>

    function OnCreated() {

        document.getElementById("listbox_parent").ondblclick = () => {

            var listBox = ej.base.getComponent(document.querySelector('#listbox'), 'listbox');

            var textBox = ej.base.getComponent(document.querySelector('#default'), 'textbox');

            textBox.value = listBox.value;

        };

    }

</script>


Could you please check the above code and get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar A


Marked as answer

EW Eddie Willcox replied to YuvanShankar Arunagiri June 24, 2022 08:44 AM UTC

Thank you. This is exactly what I wanted.



YA YuvanShankar Arunagiri Syncfusion Team June 27, 2022 11:32 AM UTC

You are welcome, Eddie. We are happy to hear that your requirement has been fulfilled. Please get back to us if you need any further assistance on this.


Loader.
Up arrow icon