Monday, 9 September 2013

issue in reading a value of textbox line by line in javascript

issue in reading a value of textbox line by line in javascript

I am wondering how I can get the value inside a pre element (line by line)
after a user click enter. The problem with my code is that it gets all the
value from the beginning to the last value the user enters.
events : {
"keypress :input" : "cliKeyPressed",
},
cliKeyPressed : function(e) {
if(typeof e === "undefined" ) e = window.event;
if(e.keyCode == 13) {
var previousLine = "";
console.log(document.getElementById("terminal").innerHTML);
if($('#terminal').text()!== ""){
previousLine = $('#terminal').text();
previousLine = previousLine.replace("laura-1$>", "");
}
var inputData = $(e.currentTarget).val();
$('#terminal').text(previousLine + "\r\n" + inputData +
"\r\n");
$("#textInput").val("laura-1$>");
}
if(previousLine != ""){
$("#terminal").empty();
var command = $('#terminal').val();
console.log(command);
}
if(e.keyCode == 17){
console.log("asdasd");
$("#terminal").empty();
}
},

No comments:

Post a Comment