Skip to content Skip to sidebar Skip to footer

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:

functioneraseText() {
    document.getElementById("txt").value = "";
}

functiondisplayOut() {
    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 displayOutand 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.

functiondisplayOut() {
  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.

}

functioneraseText() {
  document.getElementById("txt").value = "";
}
<h1id="result">Javascript Exm</h1><textareaid="txt1"rows="10"cols="100"readonly="readonly"></textarea><textareaid="txt"rows="4"cols="50"onclick="eraseText()"></textarea><inputtype="button"onclick="displayOut()"value="click">

Solution 3:

functiondisplayOut(){
    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();
    }
}
functioneraseText()
{
    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"