After working on the provided code, I have managed to create a functionality where text from one textarea is copied to another textarea when a button is clicked using JavaScript.
<head>
<script type="text/javascript">
function displayOut(){
var input=document.getElementById("txt").value;
var text2=document.getElementById("txt1");
text2.value=input;
if(input.length===0)
{
alert("Please enter a valid input");
return;
}
function eraseText() {
document.getElementById("txt").value = "";
}
}
</script>
<body>
<h1 id="result">Javascript Exm</h1>
<textarea id="txt1" rows="10" cols="100" readonly="readonly" ></textarea>
<textarea id="txt" rows="4" cols="50" onclick="eraseText()"></textarea>
<input type="button" onclick="displayOut()" value="click">
</body>
However, there are modifications that I still need:
When the button is clicked, the text should be copied to the second textarea and the original text in the first textarea should be cleared. I tried using an erase function but it did not work as expected.
I also want the copied text to be displayed in the second textarea in a continuous format, one below the other, upon clicking the button.