Jquery submit select form when option is selected

javascript c# jquery html forms

302 просмотра

1 ответ

310 Репутация автора

I have a select, with a long list, in which i can search it, with select2 jquery pluing.

my select:

 @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>

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

I need it to be able to let me search and select the option i want to use. press enter or mouse click. and then it submits the form...

and offcourse it has to work with a normal submit button aswell...

i have tried this code:

$(document).ready(function () {
        $('#clientform').on('change', function () {
            var $form = $(this).closest('form').on('change', function () { 

in which it submits before i even search, though it works if i just normally scrolls through the list and clicks..

Автор: andrelange91 Источник Размещён: 22.09.2016 08:46

Ответы (1)

4 плюса

29403 Репутация автора


If you want to submit the form after you change the select option do:

$('.selectpicker').on('change', function () {
Автор: madalinivascu Размещён: 22.09.2016 08:49
Вопросы из категории :