Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
How to check multiple fields and change value based on drop down option

I have a dropdown list and an input field, I want to check if the input field equals to a specific value e.g. G2 and if the drop-down is changed to a specific value e.g. option 1 then I want to show a value on another input field.

I made an example of what I am currently doing now which only works if onblur is triggered on G2 field.

   <select name="beModel" id="beModel" onchange="selectModel(event)" 
      onblur="checkGas(event)" >
                <option value="0">Select test</option>
                <option value="1">test 1</option>
                <option value="2">test 2</option>
            </select>
      
      <input name="input1" type="text" id="text1" value="" size="20" 
      maxlength="100">
      
      <input name="input2" type="text" id="text2" value="" size="20" 
      maxlength="100">
      
      <input name="input3" type="text" id="check" 
      onblur="checkGas(event)" value="G2" size="20" maxlength="100" >
      
      <input name="input4" type="text" id="change" value="" size="20" 
      maxlength="100" >

      function checkGas(e){
         if (e.target.value == "G2"){
    
         document.getElementById("change").value = "7.4m3/h"

        } 
      }

    function selectModel(e) {

       if (e.target.value == 1){
          document.getElementById("text1").value = "4 bars"
          document.getElementById("text2").value = "4 bar"
    
       }
       else if (e.target.value == 2){
          document.getElementById("text1").value = "6 bars"
          document.getElementById("text2").value = "6 bar"
    
        }
    }

https://jsfiddle.net/rwvnc7y3/9/

What I want is to trigger this effect while changing the drop-down option instead of triggering onblur on G2 field, is there a simple solution for this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I hope this is what you are asking, please check the code below:

function selectModel(e) {
if(document.getElementById("check").value=="G2"){
if (e.target.value == 1){
        document.getElementById("text1").value = "4 bars"
        document.getElementById("text2").value = "4 bar"
    
}
    else if (e.target.value == 2){
        document.getElementById("text1").value = "6 bars"
        document.getElementById("text2").value = "6 bar"
    
}
document.getElementById("change").value = "7.4m3/h"
}   
}
<select name="beModel" id="beModel" onchange="selectModel(event)" >
                <option value="0">Select test</option>
                <option value="1">test 1</option>
        <option value="2">test 2</option>
            </select>
      
      <input name="input1" type="text" id="text1" value="" size="20" maxlength="100">
      
      <input name="input2" type="text" id="text2" value="" size="20" maxlength="100">
      
      <input name="input3" type="text" id="check" onblur="checkGas(event)" value="G2" size="20" maxlength="100" >
      
      <input name="input4" type="text" id="change" value="" size="20" maxlength="100" >

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda