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

173
Visualizações
get last typed and changed input

I need help with this.

I have 3 inputs, one type=range and the other two type=text.

I have managed that the three inputs are related. That is, if i change one input, the other inputs change too. In this part, the code works fine

My problem is that i want to return a variable that equals to 0 or 1 deppending of the element changed.

Let me explain, if the user move the cursor of the type range, or type in the first input, elmChanged return 1. But, in the other case, if the user type in the second input, elmChanged return 0

I have tried using onchange, and onkeyup, but, i couldn't find a solution, because, if i change the value of one input, the other two inputs change too. I have tried using also onkeyup, but i neither couldn't find a solution because i couldn't manage how to change the value of elmChanged.

My question is how can i do this and where to load elmChanged depending of the last element changed.

var elmChanged = ""

    function RangeChanged(){
        amountInput.value=amountRange.value; 
        amountInput_2.value=amountRange.value * 2
        // how can i do that
        elmChanged = 1
    }

    function FirstInputChanged(){
        amountRange.value=amountInput.value; 
        amountInput_2.value=amountInput.value * 2;
        // how can i do that
        elmChanged = 1
    }

    function SecondInputChanged(){
        amountRange.value=amountInput_2.value; 
        amountInput.value=amountInput_2.value / 2;
        // how can i do that
        elmChanged = 0
    }

console.log(elmChanged)
ElementInputChanged.value = elmChanged 
<form>
  <input type="range" name="amountRange" id="amountRange" min="0" max="100" value="50" step="1" oninput="RangeChanged()"  />
  <input type="text" name="amountInput" id="amountInput" min="0" max="100" value="50" oninput="FirstInputChanged()"  />
  <input type="text" name="amountInput_2" id="amountInput_2" min="0" max="200" value="100" oninput="SecondInputChanged()" />
        
  <span>Element Changed:</span> <span id="ElementInputChanged"></span>

</form>

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

0

You can pass it to a function. By the way: span doesn't have value like inputs. I changed it to textContent.

Snippet:

/*var elmChanged = ""*/

function RangeChanged(){
  amountInput.value=amountRange.value; 
  amountInput_2.value=amountRange.value * 2
  // how can i do that
  elmChanged(1);
}

function FirstInputChanged(){
  amountRange.value=amountInput.value; 
  amountInput_2.value=amountInput.value * 2;
  // how can i do that
  elmChanged(1);
}

function SecondInputChanged(){
  amountRange.value=amountInput_2.value; 
  amountInput.value=amountInput_2.value / 2;
  // how can i do that
  elmChanged(0);
}
function elmChanged(num) {
  console.log(num)
  ElementInputChanged.textContent = num
}
<form>
  <input type="range" name="amountRange" id="amountRange" min="0" max="100" value="50" step="1" oninput="RangeChanged()"  />
  <input type="text" name="amountInput" id="amountInput" min="0" max="100" value="50" oninput="FirstInputChanged()"  />
  <input type="text" name="amountInput_2" id="amountInput_2" min="0" max="200" value="100" oninput="SecondInputChanged()" />
        
  <span>Element Changed:</span> <span id="ElementInputChanged"></span>

</form>

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