Text From One Textarea Should Get Copy To Another Textarea And Original Textarea Should Be Cleared On A Button Click Using Javascript
i have done with following code it displays two textarea where the text from one textarea gets copied to another textarea on a button click using javascript but I need that: On a
Solution 1:
Try:
function eraseText() {
document.getElementById("txt").value = "";
}
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;
}
eraseText();
}
Demo: http://jsfiddle.net/GCu2D/840/
You should move eraseText()
out of displayOut
and then call it inside displayOut
Solution 2:
Try this one, you did little mistake , your eraseText()
move out from displayOut()
. and call eraseText()
function after copied text in second textarea.
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;
}
eraseText(); //call function to erase text in textarea.
}
function eraseText() {
document.getElementById("txt").value = "";
}
<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">
Solution 3:
function displayOut(){
var input=document.getElementById("txt").value;
if(input.length===0)
{
alert("Please enter a valid input");
return;
}else{
var text2=document.getElementById("txt1");
text2.value=input;
eraseText();
}
}
function eraseText()
{
document.getElementById("txt").value = "";
}
Post a Comment for "Text From One Textarea Should Get Copy To Another Textarea And Original Textarea Should Be Cleared On A Button Click Using Javascript"