user1150125
user1150125

Reputation: 89

Trying make a terminal shell like webpage, why this dosen't work?

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>&nbsp;
    <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

Answers (2)

Sri Harsha Velicheti
Sri Harsha Velicheti

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

Herman Tran
Herman Tran

Reputation: 1591

You just need to add the id selector to your jQuery element: $("#command")

Upvotes: 2

Related Questions