title: Add text to a textarea with JavaScript
body: <p>Again I got a problem with JavaScript, but this time is something more complex.</p>
  <p>I'm trying to make a little JavaScript text editor. Basically it's an experiment, a test and the thing should be easy. I have a <code>&lt;h1&gt;</code> HTML element, and a <code>&lt;p&gt;</code> HTML element, and both of them change, as the user writes on a <code>&lt;input type=&quot;text&quot; /&gt;</code> element and a <code>&lt;textarea&gt;&lt;/textarea&gt;</code>.</p>
  <p>Now, everything work fine, but there is a problem. For making a space between lines, the user can't just press <kbd>Enter</kbd>, but of course need to use the <code>&lt;br /&gt;</code> HTML tag.</p>
  <p>So my idea was to make a little button that allows the user to add this tag by pressing that button.</p>
  <p>And JavaScript just makes a variable of the actual text, save it and add at the end of it the <code>&lt;br /&gt;</code>. The result should be the text written by the user plus the break HTML tag.</p>
  <p>And this works, if the textarea is empty and if you have never written something on it. It works and work even 10 or 20 times, but if you write something on it, it just stop working, even if you delete all the text. What is the problem in the code below?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Text editor&lt;/title&gt;
          &lt;meta charset="utf-8" /&gt;
          &lt;link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Slab" rel="stylesheet"&gt;
  
          &lt;style&gt;
              .title {
                  font-family: roboto;
                  text-align: center;
              }
              .text {
                  font-family: roboto slab;
                  text-align: justify;
                  margin-bottom: 40px;
              }
              .container {
                  width: 80%;
              }
              .textarea {
                  width: 100%;
                  height: 30em;
                  text-indent: 0.5em;
              }
              .title_box {
                  margin: 10px;
                  width: 20em;
                  padding: 10px;
                  font-size: 1em;
              }
          &lt;/style&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;center&gt;
          &lt;div class="container"&gt;
              &lt;h1 class="title" id="title_space"&gt;Title of the page&lt;/h1&gt;
              &lt;p class="text" id="text_space"&gt;Content of the page.&lt;/p&gt;
          &lt;/div&gt;
          &lt;/center&gt;
          &lt;hr /&gt;
          &lt;center&gt;&lt;input type="text" class="title_box" placeholder="Title" id="title_box" /&gt;&lt;/center&gt;
          &lt;textarea class="textarea" id="text_box"&gt;&lt;/textarea&gt;
          &lt;input type="submit" value="Save" onclick="saveText()" /&gt;
          &lt;input type="submit" value="br" onclick="br()" /&gt;
  
          &lt;script&gt;
              function saveText(){
                  var title = document.getElementById("title_box").value;
                  var text = document.getElementById("text_box").value;
  
                  document.getElementById("title_space").innerHTML = title;
                  document.getElementById("text_space").innerHTML = text;
              }
  
              function br(){
                  var actualtext = document.getElementById("text_box").value;
                  var processedtext = actualtext + "&lt;br /&gt;";
                  document.getElementById("text_box").innerHTML = processedtext;
              }
          &lt;/script&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>