我的视图中有一个下拉列表、一个提交按钮和一个文本框。我想在单击提交按钮或 dropdownlist 的 onChange 事件时将 dropdownlist 的选定值传递到文本框。我怎样才能实现这个目标?
我解决如下:
<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>
I want to pass the selected value of dropdownlist to the textbox when
the submit button is clicked or onChange event of dropdownlist
$(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
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)