Q:

How to call a function in Javascript when a input changes value?

How to call function xxx when input type text id="username" change value ?
first, when you fill data into 
<input type="text" name="thingy" onkeypress="updateInput(this.value)" onkeyup="updateInput(this.value)" />

Then data in
<input type="text" name="thingy" onkeypress="updateInput(this.value)" onkeyup="updateInput(this.value)" />

will change value.
OK, when input name="thingy" change i want to call function xxx , i try this code but not work.
How can i do that ?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function updateInput(ish){
    document.getElementById("username").value = ish;
}
</script>
<form id="main_fid">
    input1 : <input type="text" name="thingy" onkeypress="updateInput(this.value)" onkeyup="updateInput(this.value)" /> 
    <span id="mySpan"></span>
    <input type="submit" value="OK"/>
</form>

<script>
function xxx() {
        $.ajax
        (
            {
                url: 'other.php',
                type: 'POST',
                data: $('#username_send_value_fid').serialize(),
                cache: false,
                success: function (data) {
                    $('#mySpan').show();
                    $('#mySpan').html(data);
                }
            }
        )
}
</script>
<br>
<form id="username_send_value_fid">
    input2 : <input type="text" name="username" id="username" onchange="xxx()" readonly/>  
</form>

A:

I think calling xxx() on "onchange" event or inside updateInput(ish) will give the same effect.
Try
function updateInput(ish){
  document.getElementById("username").value = ish;
  xxx();
}

