Display chosen Select value

Asked

Viewed 91 times

1

I have this dropdownlist:

 <select>
                <option value="0">Selecione os capitulos</option>
                @foreach (var item in ViewBag.Capitulos)
                {
                    <option value="@item.IdCapitulo">@item.TituloCap</option>
                }

            </select>

How do I display the chosen value on the same page? I want the user when choosing the chapter to automatically load the user’s choice into a textarea below. You can do this?

1 answer

1


I made this example using jQuery:

$(document).ready(function(){
  $('.capitulos').on('change', function(){
     $('.escolhido').text($(this).val());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class='capitulos'>
   <option value=''>Selecione...</option>
   <option value='1'>Capítulo 1</option>
   <option value='2'>Capítulo 2</option>   
</select>

<textarea class='escolhido'></textarea>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.