I have an input form that is being dynamically updated with JavaScript. Using d3, I want to create an event listener that will run a function every time this input is manipulated.
Currently, it will run if I manually change the input field, but not if it is updated using the JavaScript. I have tried using .on("change",...
and .on("input",...
.
Here is an example of the functionality I am trying to get:
<!DOCTYPE html>
<meta charset="utf-8">
<input value="0" id="input1">
<button onclick="clickFunc();">Click Me</button>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
d3.select("#input1").on("input", function() {
// not printing when updated by javascript
console.log('value changed');
});
function clickFunc() {
document.getElementById('input1').value = document.getElementById('input1').value + 1;
}
</script>