Search code examples
javascriptjqueryhtmltextarea

How to copy from one textarea to another?


I have one page, with two textarea elements. How do I copy the text from one textarea to another?

<textarea id="one"></textarea>
<textarea id="two"></textarea>

So text area one is primarily where the data appears, I need to copy it to text area two during the onchange event.


Solution

  • This is how I would do it:

    $("#one, #two").on("change keyup", function(){
        $("textarea").not($(this)).val($(this).val());
    });
    

    Here is the JSFiddle demo

    The code will synchronize both textareas