Passing drop-down list values ​​to a text field

I have a drop-down list, a submit button and a text box in my opinion. I want to pass the selected dropdownlist value to the text box when the submit button or the onChange event from the drop-down list is clicked. How can i achieve this ??

I solved it as follows:

<script type="text/javascript"> $(function() { $('#ddlComp').change(function() { var selectedValue = $(this).val(); $('#txtCompName').val(selectedValue); }); }); </script> <div> @Html.DropDownList("ddlcomp", Model.CompanyList) <input type="submit" value="Submit" /> @Html.TextBox("txtCompName") </div> 
+4
source share
1 answer

I want to pass the selected value of the drop-down list to the text box when the submit button is pressed or the onChange event from the drop-down list

 $(function() { var selectedValue = ''; // declare variable here // on drop down change $('#ddlComp').change(function() { selectedValue = $(this).val(); // store value in variable $('#txtCompName').val(selectedValue); // update on change }); // on submit button click $('input[type=submit]').click(function(){ $('#txtCompName').val(selectedValue); // update on submit button }); }); 
+1
source

All Articles