I want the event to change every time in the HTML text input field regardless of focus

How do you catch a client side event when the browser changes the input text field using the browser autocomplete feature for the normal HTML input field? (This is a small dropdown list of input fields that is provided by the browser, I know you can turn it off with "autocomplete = off" in some browsers per input field.)

I already bind to the "change / keyup" event, but they don't handle the case where the user starts typing and uses the browser's own autocomplete to fill in the rest of the field (and stay focused on the field.)

+1


a source to share


3 answers


The only reliable way I know to always catch ALL changes no matter how they are made is to use setInterval. This is mainly processor intensive, so you probably want the selector to be more minimal than that.



setInterval( function() {
    $('input').each( function() {
        if ($(this).val() != $(this).attr("_value")) {
            // Save the new value
            $(this).attr("_value", $(this).val());

            // TODO - Handle the changed value
        }
    });
}, 100);

      

+4


a source


I'm surprised the "change" event doesn't fire, to be honest ...

Either way, Plutor has the right idea. A cleaner version of his answer:



var value,
    elem = $('input[name=email]')[0];
setInterval(function(){
    if (elem.value !== value) { /* do something */ }
    value = elem.value;
}, 100);

      

+1


a source


you can call your function in your function next time many seconds later try this:

function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML = h+":"+m+":"+s;
    var t = setTimeout(function(){startTime()},500);
}

function checkTime(i) {
    if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
      

<!DOCTYPE html>
<html>
<head></head>
<body onload="startTime()">

<div id="txt"></div>

</body>
</html>
      

Run codeHide result


link: http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock

0


a source







All Articles