Reputation: 142
I have a button and I have an input1 field in HTML file. When the button clicked, server returns a value incremented by one and displayed in input1 field.
In javascript file: For time performance test: I want to save time (milliseconds) when the button clicked, and I want to save time when incremented value returns from server in the input1 field.
Is there some kind EventListener in JS that detects value change made by server in an input field?
I have tried addEventListener but does not work, as you know, it only detects changes made by user. Please point me in the right direction.
function myFunction() {
var mss = performance.now();
document.getElementById("time").innerHTML="Click Time in milliseconds: "+mss;
document.input1.addEventListener("change", getTime(mss),false);
}
function getTime(e){
var rt = performance.now();
var ms = e;
var diff= rt-ms;
document.getElementById("returnTime").innerHTML="Return time in milliseconds:"+ ms;
document.getElementById("timeDiff").innerHTML="Time Difference in milliseconds:"+ diff;
}
Upvotes: 0
Views: 3742
Reputation: 2701
You are calling the function getTime this line, instead of in the event listener.
document.input1.addEventListener("change", getTime(mss),false);
I believe what you want to do instead is:
document.input1.addEventListener("change", getTime.bind(null, mss),false);
Upvotes: 3