Vikash Pandey
Vikash Pandey

Reputation: 4285

adding texts in to textbox by selecting the value from dropdown

i have two dropdown one in ajax and other one is in html i want to add the value of dropdown in to textbox from each of the dropdown.how to add the selected value in to the text box?? my code is

        <script type="text/javascript">
        $(document).ready(function () {
        $.ajax({
            url: 'ListOfEmployees',
            success: function (data) {
                $.each(data, function (i, e) {
                    $('#DepartmentId').append('<option value="' + e.DepatID + '">' + e.DepartmentName);
                      var myValue = $(this).val();
                });
            }
        });
    });
</script>

        <td>
            <%=Html.DropDownList("ForModalityID", new SelectList(Model.ModalityList, "ModalityID", "ModalityDisplayName"))%>
        </td>

         <td>Name </td><td>
    <%= Html.TextArea("sfv") %>
    </td>

i am new in this field.i am not able to add the selected value of dropdown in text area.... Help me ....thanks

Upvotes: 0

Views: 605

Answers (1)

Derk Arts
Derk Arts

Reputation: 3460

Try this:

$('select').change(function(){
       $('#IdOfText').html($(this).val();)
});

You bind a .change() event to the <select> which gets the value of that <select> and sets it as the html for you text box.

$.html(): http://api.jquery.com/html/

$.change(): http://api.jquery.com/change/

$.val(): http://api.jquery.com/val/

Upvotes: 2

Related Questions