Using document.write in event handler?
- by StackedCrooked
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?