Using document.write in event handler?

Posted by StackedCrooked on Stack Overflow See other posts from Stack Overflow or by StackedCrooked
Published on 2010-05-05T18:25:51Z Indexed on 2010/05/05 18:58 UTC
Read the original article Hit count: 244

Filed under:
|

I am experimenting with HTML and JavaScript. The following code should print something when entering a keystroke in a textbox:

<html>
    <body>
        <input type="text" id="commandInput" name="command" size="50" />
        <script type="text/javascript">
            var commandInput = document.getElementById("commandInput");
            commandInput.onkeydown = function (evt) {
                document.writeln("Test");
            };
        </script>    

    </body>
</html>

For some reason the textbox disappears when entering a keystroke, leaving nothing but a white page.

Any ideas why this is happening?

© Stack Overflow or respective owner

Related posts about html

Related posts about JavaScript