Reputation: 89
I'm trying to make a terminal shell like webpage,type something in text input field then hit enter to print it out then scroll the prompt, I have no idea what exactly to do, so this just a very easy test, but why dosen't it work? http://jsfiddle.net/paopaomj/qGw4Q/1/ I write it on jsfiddle, not sure how to post embeded code on stackoverflow, so code below already has those javascript and jquery loading statement. I'm such a newbie at coding, so thank you for your help.
html:
<body>
<div id="output"></div>
<div id="input">
<span>root@host</span>
<input type="text" id="command" />
</div>
javascript:
$("command").keyup(function (e) {
if (e.keyCode == 13) {
submit();
}
});
var submit = function () {
var command = document.getElementById("command").value;
var outputel = document.getElementById("output");
var div = document.createElement("div");
div.innerHTML = "root@host " + command;
outputel.appendChild(div);
};
Upvotes: 1
Views: 433
Reputation: 497
you were missing # in the jquery selector $("#command"). For jquery to select the dom element by id the selector syntax is # followed by id
$("#command").keyup(function (e) {
if (e.keyCode == 13) {
submit();
}
})
Upvotes: 1
Reputation: 1591
You just need to add the id selector to your jQuery element: $("#command")
Upvotes: 2