Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
  
<html>
    <head>
        <script>
            document.addEventListener ("DOMContentLoaded", function () {
                var input = this.getElementsByTagName ("input")[0];
                var div = this.getElementsByTagName ("div")[0];
                var i = 0;
                var seconds = 5;
                div.innerHTML = "The following input should fire the event in " + seconds + " seconds";
                var interval = window.setInterval (function () {
                    var event;
                  
                    i ++;
                    if (i === seconds) {
                        window.clearInterval (interval);
                        input.value = "Another example";
                      
                        event = new UIEvent("change", {
                            "view": window,
                            "bubbles": true,
                            "cancelable": true
                        });
                        input.dispatchEvent(event);
                        div.innerHTML = "See, something happened !";
                    }
                    else {
                        div.innerHTML = "The following input should fire the event in " + (seconds - i) + " seconds";
                    }
                }, 1000);
                input.addEventListener ("change", function () {
                    alert ("It works !");
                }, false);
            }, false);
        </script>
        <style>
            body {
                padding: 10px;
            }
            div {
                font-weight: bold;
                margin-bottom: 10px;
            }
            input {
                border: 1px solid black;
                border-radius: 3px;
                padding: 3px;
            }
        </style>
        <title>Event</title>
    </head>
    <body>
        <div></div>
        <input type = "text" value = "Example" />
    </body>
</html>
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers