The “onchange” event does not work with “value” change in “text input” object

What browser are you using?

I have made this example, which works for me… the subtle change is that I add the event to the input before I append it to the div element.

<div id="test"></div>
<script type="text/javascript">
    var id_box = document.createElement('input');
    id_box.type="text";
    id_box.onchange = function()
    {
        alert("Changed!");
    }
    document.getElementById("test").appendChild(id_box);

</script>

See it in action on JS Fiddle: http://jsfiddle.net/Sohnee/zCMdV/

Update:

If you are going to automate the changing of the value, you can do the same to trigger the change event…

http://jsfiddle.net/Sohnee/zCMdV/10/

document.getElementById('id_box').onchange();

Leave a Comment