I'm finally getting around to learning Javascript; I am trying to do something simple: capture keyboard input while providing output. I get semi-responsive output for keyboard presses, however I am not able to append the output portion of the page with a line of input once enter is pressed. What am I doing wrong?
<script language="javascript">
processCommand = function(cmd) {
if (this.text == null) this.text = "";
this.text = this.text + cmd + "<br>";
document.getElementById("outputID") = this.text;
}
document.onkeydown = function(evt) {
if (this.text == null) this.text = "";
var keyChar = String.fromCharCode(evt.keyCode);
this.text = this.text + keyChar;
if (evt.keyCode == 13) {
processCommand(this.text);
this.text = "";
}
document.getElementById("input").innerHTML = this.text;
};
</script>
<spad id="outputID"/><br>
<hr>
<spad id="input"/>
document.getElementById("outputID").innerHTML = this.textnotdocument.getElementById("outputID") = this.text;.document.getElementById("outputID")anddocument.getElementById("input")elements. No need to look them up on every key press