Q:

detect event from $("input").val() and then run function js

I want to recognize a function event with "on" and then run console.log but input, keyup, keydown or change doesnt call this change.
I have the write function.
function write(){
  $("input").val("1");
}

And then this query for checking the event:
$("input").on("change",function(){
  console.log('input changed!');
});

write();//it doesnt get the change function

Custom HTML:
<input type="text">

The reason of this is that i want to enter values with a custom js keyboard (that's why i cant use keyup or keydown) but i cant get the event of .val() from jquery.

A:

You have to trigger the event after you set .val - jQuery doesn't trigger events automatically when you change it in code.

function write(){
  $("input").val("1").trigger("change");
}

$("input").on("change",function(){
  console.log('input changed!');
});

write();//it doesnt get the change function
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text">

