How to submit a form with select without submit button?

1

Good evening, how do I submit a form with select without the submit button? For example, to create a filter that when you select the option it automatically submits the form without having the submit button.

My form looks like this:

<form class="form-inline left" method="POST">
            <div class="form-group">
                <label for="listar">Listar por</label>
                <select id="filtro" name="filtro" class="form-control">
                    <option value="professor">Professor</option>
                    <option value="assunto">Assunto</option> 
                </select>
            </div>
        </form>
    
asked by anonymous 22.11.2016 / 21:05

1 answer

1

You can do this directly on select with onchange="this.form.submit()" :

<select id="filtro" name="filtro" class="form-control" onchange="this.form.submit()">

This way when the change event is created it sends the form directly.

Example: link

Another way is to use an event sounder like this:

document.getElementById('filtro').addEventListener('change', function() {
    this.form.submit();
});

Example: link

    
22.11.2016 / 21:07