title: Assign a selected <select> option to an input's value
body: <p>I have a <code>&lt;select&gt;</code> with 4 <code>&lt;option&gt;</code>s and I'm trying to get the selected option into a value of a <code>&lt;input type="hidden"&gt;</code>.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;form id="selector" name="selector" action="" method="get"&gt;
                  &lt;label&gt;Number of players: &lt;/label&gt;&lt;select form="selector" id="selectelement"&gt;
                      &lt;option value="2"&gt;2&lt;/option&gt;
                      &lt;option value="3"&gt;3&lt;/option&gt;
                      &lt;option value="4"&gt;4&lt;/option&gt;
                      &lt;option value="5"&gt;5&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;input type="hidden" id="numofplayers" /&gt;
                  &lt;label&gt; Board size: &lt;/label&gt;&lt;input type="number" id="board_size" maxlength="2" style="max-width: 20px;" name="board_size" min="3" max="20" /&gt;
                  &lt;label&gt; Sequence to win: &lt;/label&gt;&lt;input type="number" id="win_size" maxlength="1" style="max-width: 10px;" name="win_size" min="3" max="9" /&gt;
                  &lt;input type="submit" name="submit" value="Go" /&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>function goform()
  {
      this.form.elements["numofplayers"].value =  document.getElementById('selectelement').selectedIndex.innerHTML;
  }
  </code></pre>
  
  <p>and in the form tag i do that: </p>
  
  <pre><code>&lt;form onsubmit="goform()" id="selector" name="selector" action="" method="get"&gt;
  </code></pre>
  
  <p>How do I do that?</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: Sorry, I solved it, appearently you can get the value of a selected option by just doing that:</p>
  
  <pre><code>var x = document.getElementById("selectelement").value;
  </code></pre>
  
  <p>Thanks anyway.</p>