Is it possible to somehow add template text to <textarea> ? Suppose there is a button on the site (implemented through <a> or <input> ), by clicking on which a template line will be added to the text input field. Or is it better to do all this through a <div> ?

    1 answer 1

    Here is an example:

     <!DOCTYPE html> <html> <body> <textarea id="myTextarea"> Какой-то текст, бла бла </textarea> <br> <button type="button" onclick="myFunction()">Жми</button> <script> function myFunction() { document.getElementById("myTextarea").value = "Пример текста"; } </script> </body> </html> 

    Example

    • And can this be done without harming the entire text? Those. just add at the end of the sentence - NTP
    • Did not quite understand what you need :) - user242433
    • one
      document.getElementById ("myTextarea"). value = document.getElementById ("myTextarea"). value + "Sample Text"; - Rostyslav Kuzmovych
    • @RostyslavKuzmovych, exactly, thanks - NTP
    • one
      Or using Jquery, $('a').click(function(){ var text = "text"; $('#myTextarea').append(text); });​ user242433