Change select when input is completed

Asked

Viewed 130 times

0

inserir a descrição da imagem aqui

If the field "PANTONE" input is filled in, the field select "LINEATURA" is automatically set to "52".

In PHP or JS

1 answer

0


Hello, I made an example solving your problem!!! Using only the javascript functions getElementById and selectedIndex. To test locally just run the following code in a browser, save it in a file .html and run in your browser.

<!DOCTYPE html>
<html>
<body>
<h3>Pantone</h3> <input type="text" id="pantone" onkeyup="verificarSelect();"/>
<br><br>
<select id="lineatura">
  <option value="volvo">SELECIONE</option>
  <option value="volvo">52</option>
  <option value="saab">42</option>
  </select>


 <script> 
    function verificarSelect(){
    var lineatura = document.getElementById('lineatura');
    var pantone = document.getElementById('pantone');

        if(pantone.value != ""){ // Se o valor for preenchido, setar o SELECT para 52
             lineatura.selectedIndex = 1; //Indice da opção 52
        }
        if(pantone.value == ""){ // Caso esteja vazio, selecionar alguma opção
             lineatura.selectedIndex = 0;
        }
    }


 </script>
</body>
</html>

To test remotely use: https://codepen.io/anon/pen/LgBBqx

I hope I’ve helped!

  • 1

    Very cool the solution André! I recommend putting a snippet of your code so that users who view your answer can also test and see working.

  • Thanks @Joãopedroschmitz!

  • PERFECT ! Exactly what I needed.

  • Great to know it served! Hugs @Júlioricardo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.