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

121
Views
set new value with windows.prevFocus

I have set up previous focus storage in my document. When the button is clicked, a function gets executed. The value 0 is transported as a variable from the button to the function. In the function the new value is set to the previous focussed element. But it doesn't work. Why not? The reason why I do it this way is because I have more buttons, that give different values but only have to use the same function: setNewValue

Main script:

window.prevFocus = $();
// Catch any bubbling focusin events (focus does not bubble)
$(document).on('focusin', ':input', function () {
   // Test: Show the previous value
   $("#debug").html(prevFocus.attr("id"));
   // Save the previously clicked value for later
   window.prevFocus = $(this);
});

Button script

$("#butSetVal0").on({ 
    click: function(){
        newVal = 0;
        setNewValue(newVal);
    }
});

set new value script:

function setNewValue(newVal){
    prevFocus.val(newVal).trigger("input");
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I fixed it already. The solution is to set the eventhandler of the button on 'mousedown'. The 'click' trigger detects two clicks. The second click interprets as the previous focus element, so the button itself.

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!