i have a cascading dropwdown lists done in Jquery they work pretty well but i have a problem with submiting a form when the second dropDown change, here is my code.
$("#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();
});
the form only submits when i select a value from the dropdown but when the first dropwdown fills with data the second one, it does not submit the form.
Update Added 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
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.