title: How to add user input to a JavaScript array
body: <p>I am in the process of learning JavaScript and jQuery, so apologies if any of this sounds naive or obvious. I started what I thought was a fairly simple project to practice and hopefully learn something in the process. </p>
  
  <p>What I want to do is this: the user inputs a sentence and hits a submit button. The sentence gets added to a list of other sentences submitted by people (preferably on a separate file, preferably encrypted, but not necessary). Then, the website grabs a random sentence from the list and displays it. </p>
  
  <p>I am not asking on how to build all of this. I have already put most of it together, but I am including it here for reference. </p>
  
  <p>I have a separate javascript file with the array of quotes.</p>
  
  <pre><code>var quotes=new Array();
  quotes[0]="&lt;p&gt;Quote 1&lt;/p&gt;";
  quotes[1]="&lt;p&gt;Quote 2&lt;/p&gt;";
  quotes[2]="&lt;p&gt;Quote 3&lt;/p&gt;";
  quotes[3]="&lt;p&gt;Quote 4&lt;/p&gt;";
  quotes[4]="&lt;p&gt;Quote 5&lt;/p&gt;";
  quotes[5]="&lt;p&gt;Quote 6&lt;/p&gt;";
  quotes[6]="&lt;p&gt;Quote 7&lt;/p&gt;";
  </code></pre>
  
  <p>Then I randomly display one using this:</p>
  
  <pre><code>function getQuote(){
              var thisquote=Math.floor(Math.random()*(quotes.length));
              document.write(quotes[thisquote]);
            }
  </code></pre>
  
  <p>And adding <code>&lt;script&gt; getQuote(); &lt;/script&gt;</code> to the html.</p>
  
  <p>This all works fine.</p>
  
  <p>The part I cannot seem to figure out is taking user input and adding it to the jQuery array. I am using a <code>contenteditable</code> div instead of an <code>&lt;input&gt;</code> because I want it to have multiple lines of text and have a character limit, which as far as I know can only be done with a contenteditable div (according to the research I did at the time, I may be wrong).</p>
  
  <p>I have looked around and tried many if not all the examples I found of how to do this, and none of them worked. This is the last method I tried, if it helps:</p>
  
  <pre><code>$(".submit").click(function() {
      quotes[quotes.length] = document.getElementsByClassName("input").value;
  });
  </code></pre>
  
  <p>So, to reiterate, I want to take user input and add it to a JavaScript array. I have scoured stackoverflow and the interet but nothing has worked. Please help!</p>
  
  <p><strong>UPDATE:</strong> Arvind got it right. I still have a lot to learn, and it seems I need to read up on localstorage and cookies. I will also need to use PHP to save the sentences on the server. Thank you to all who answered!</p>