[英]Submit Form on Cascading DropDown Change Jquery
我在Jquery中完成了一個級聯的dropwdown列表,它們工作得很好,但是當第二個dropDown更改時我提交表單存在問題,這是我的代碼。
$("#Bank").change(function () {
var bankId = $(this).val();
$.ajax("/App/BankBranch/ByBank", {
data: { "id": bankId },
type: "get", contentType: "application/json",
success: function (result) {
var options = $("#id");
options.html("");
$.each(result, function () {
options.append($("<option />").val(this.Id).text(this.Name));
});
}
});
}).trigger('change'); //to make the event run on initialization for default value
$('#id').change(function() {
this.form.submit();
});
僅當我從下拉列表中選擇一個值時,表單才提交,但是當第一個下拉列表中的數據填充第二個下拉列表時,它不提交表單。
更新添加的HTML
<h2>@ViewBag.Title</h2>
<h4>Seleccione Sucursal</h4>
@using (Html.BeginForm(null, null, FormMethod.Get))
{
<div class="pull-left">
@Html.Label("Banco")
@{Html.RenderAction("GetAllBanks", "Bank", new { ControlName = "Bank" });}
</div>
<div class="pull-left">
@Html.Label("Sucursal")
@Html.DropDownList("id", Enumerable.Empty<SelectListItem>(),null ,new {name="id", @class="input-medium"})
</div>
}
$('#id').change(function() {
this.form.submit();; //double semi-colon here, remove and it should be fine
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.