Javascript DOM Textarea Split text

Description

Javascript DOM Textarea Split text

View in separate window

<!DOCTYPE html>
<head>
<script>

window.onload=function() {//from w  w w  .ja v a2 s.  c o m
  document.getElementById("preview").onclick=processText;
}

function processText() {
let   txtBox  = document.getElementById("test");
let  lines  = txtBox.value.split("\n");
let  resultString = "";

for (let i = 0; i < lines.length; i++) {
   let strng = lines[i].trim();
   resultString += strng + "-";
}
 
document.getElementById("result").innerHTML=resultString; 
}

</script>
</head>
<body>
<textarea id="test" rows="10" cols="40"></textarea>
<div><button id="preview">Preview</button></div>
<div id="result"></div>
</body>
</html>



PreviousNext

Related