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>
source share