Action using select

1

I have select

      <select class="select-sala" id="selecionar-aula">

        <option value="">Pagina 1</option>
        <option value="">Pagina 2</option>

      </select>

What I need is that when I select the página 1 it sends me to the url of Page 1 dynamically, without it being necessary to click a button and thus also with página 2 .

How can I do this?

    
asked by anonymous 17.04.2018 / 00:18

2 answers

0

I'll give my suggestion, without having to create <script> but putting it in <select>

OBS: I put the first option of <select> as "Select", because if you already enter a <option> that has a link, even selecting it, you will not be directed to the page . So I put a " placehoder " at the beginning.

See how it went in the example

select option[data-default] {
  color: #999; /* cor simulando que o campo está desabilitado depois que abre o select */
}
<select name="forma" onchange="location = this.value;">
  <option selected data-default>- Selecione -</option>
  <option value="https://pt.stackoverflow.com/">StackOverflow</option>
  <option value="https://google.com/">Google</option>
  <option value="pagina-1.php">Página 1</option>
  <option value="pagina-2.html">Página 1</option>
</select>
    
17.04.2018 / 00:36
2

var select = document.getElementById('selecionar-aula');

select.addEventListener('change', function() {
  window.location = select.value;
})
<select class="select-sala" id="selecionar-aula">
  <option value="pagina1.html">Pagina 1</option>
  <option value="pagina2.html">Pagina 2</option>
</select>

Add an event listener on the select, get the value and redirect there

    
17.04.2018 / 00:22