Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!