Submit form on any input changes with jQuery

I have a form that use selects and checkboxes.

For checkbox I use this method:

http://jsfiddle.net/nvanh/eomesgya/

The problem comes when I try to submit form on any change with:

    $('#filter_form').on('change', function () {
        console.log('submit');
    });

If I change the select option the event fire but when I check a checkbox is not.

Here is the complete code:

http://jsfiddle.net/eomesgya/2/

Upvotes: 0

Views: 1483

Answers (3)

Franklin Satler
Franklin Satler

Reputation: 320

You should bind Change Event to every input of your form, and this event should trigger the Submit event from your form.

$("#post-editor :input").each(function(){

    // Every input of your form on $(this) scope

    $(this).on('change', function () {

        $("#post-editor").submit();
    });
})

Upvotes: 0

Gene R
Gene R

Reputation: 3744

You should manually trigger change event if u manually change checked state:

$('.dropdown-menu a').on('click', function (event) {
    ....
    setTimeout(function () {
        $inp.prop('checked', true);
        $inp.trigger('change'); // add this line
    }, 0);
    ....
    return false;
});

Upvotes: 1

tempranova
tempranova

Reputation: 937

You will need to bind it to each input element in the form, not just the form itself. Maybe try something like

$('#filter_form input').each(function() { 
   $(this).on('change', function () {
        console.log('submit');
        // Do submission stuff, submit form
    });
});

https://api.jquery.com/submit/ As well if you need.

Upvotes: 1

Related Questions