How can I not load the page when clicking on the select option?

1

I have the following select, every time I select an option it reloads the page, so that's fine, but I want to make clicking on the option nUpgrade, it just does not update the page, does it have? Thanks!

    <select id="filtro" name="filtro" class="form-control" onchange="this.form.submit()">
       <option value="">Selecione</option>
       <option value="assunto"></option>
       <option value="nAtualiza"></option>
    </select>
    
asked by anonymous 24.11.2016 / 06:05

2 answers

0

You can do this:

document.getElementById('filtro').addEventListener('change', function() {
  if(this.value != 'nAtualiza') {
    console.log('submit');
    this.form.submit();
  }
});
<form> 
<select id="filtro" name="filtro" class="form-control">
   <option value="">Selecione</option>
   <option value="assunto">Assunto</option>
   <option value="nAtualiza">nAtualiza</option>
</select>
</form>

Drop the onchange event from your select and add this javascript to your file.

    
24.11.2016 / 11:40
0

Add a condition for the execution of your function.

<select id="filtro" name="filtro" class="form-control" onchange="this.value !== 'nAtualiza' && this.form.submit()">
   <option value="">Selecione</option>
   <option value="assunto"></option>
   <option value="nAtualiza"></option>
</select>

The modified snippet in the above code corresponds to this.value !== 'nAtualiza' && this.form.submit() . It's a short way of saying "run this.form.submit() if this.value is different from 'nAtualiza' ."

    
24.11.2016 / 12:09