1

I'm working on my MVC project and need to bind selected value with textbox - what I mean is when you choose an item on a selected list then this value appears in a text box. Here is an example:

            <div class="row">               
                <select id="chasis" name="type">
                
                    <option value="sedan">sedan</option>
                    <option selected value="hatchaback">hatchback</option>
                    <option value="cabrio">cabrio</option>
                    <option value="coupe">coupe</option>
                
                </select>
            </div>
                
            <label>Your choice is: <input id="chasisText" type="text" value=""></label>

and jQuery code:

    <script>
    
    $(function() {

        $("select#chasis").change(function(e){
            $("#chasisText").val(e.target.value);   
        }); 
});
    </script>

This code works well but my question is if there is any other way to show selected value in a textbox? Maybe easier or more tricky?

Muska
  • 283
  • 4
  • 15

0 Answers0