选择选项时,Jquery提交选择表单

时间:2016-09-22 08:46:04

标签: javascript c# jquery html forms

我有一个带有长列表的select,我可以使用select2 jquery pluing来搜索它。

我的选择:

 @using (Html.BeginForm("ProjectList", "Client", FormMethod.Get, new { id = "clientform", name = "clientoverviewform"}))
        {
            <div class="form-group">
                <label for="sel1">Select Client</label>
                @if (Model.ClientList != null)
                {
                    <select class="form-control selectpicker" data-live-search="true" id="sel1" name="id">

                        @foreach (var client in Model.ClientList)
                        {
                            <option value="@client.Id">@client.Name</option>
                        }

                    </select>
                }
            </div><!-- end form-group-->
            <div class="form-group">
                <input type="submit" value="Vis" class="form-control">
            </div><!-- end form-group-->
        }

我需要它才能让我搜索并选择我想要使用的选项。按输入或鼠标单击。然后它提交表单......

和offcourse它必须使用正常的提交按钮以及......

我试过这段代码:

$(document).ready(function () {
        $('#clientform').on('change', function () {
            var $form = $(this).closest('form').on('change', function () { 
                $form.find('input[type=submit]').click();
            });
        });
    });

它在我搜索之前提交,但是如果我通常滚动列表并点击那就可以了。

1 个答案:

答案 0 :(得分:4)

如果您想在更改选择选项后提交表单,请执行以下操作:

$('.selectpicker').on('change', function () {
   $(this).closest('form').submit();
});
相关问题