title: Javascript: cut string and return in different inputs
body: <p>I'm trying to cut a string in different part, and return each part into a different input. Here's an example:</p>
  
  <p>Consider the following string: <code>Hello|World|!</code></p>
  
  <p>As you can see, there is a separator, which is <code>|</code>. I'd like to separate each part of the string cut by this <code>|</code> and return them into a different input. </p>
  
  <p>I can't use <code>str.substr()</code> <em>(at least the usual use of it, maybe you have a trick)</em> because the number of characters between the <code>|</code> is not fixed, sometimes it will be 2 characters, sometimes 16, and from what I know <code>str.substr()</code> requires to set the number of characters before the cut.</p>
  
  <p>Basically I'm looking for a solution as Excel provides in the Convert feature, where you define a separator and Excel will separate each part of the value into different cells each times he finds the separator set.</p>
  
  <p>This is the first part of the Javascript, taking the value of the textarea where the string is pasted:</p>
  
  <pre><code>function cutTheString()
  {
    var str = document.getElementById('textarea').value;
  }
  </code></pre>
  
  <p>And this would be the HTML:</p>
  
  <pre><code>&lt;textarea id="textarea"&gt;&lt;/textarea&gt;
  &lt;br /&gt;
  &lt;input type="submit" value="Cut string" onClick="cutTheString()" /&gt;
  &lt;input type="text" id="string1"&gt;&lt;/input&gt;
  &lt;input type="text" id="string2"&gt;&lt;/input&gt;
  &lt;input type="text" id="string3"&gt;&lt;/input&gt;
  </code></pre>
  
  <p>For now I have <code>document.getElementById('string1').value = str();</code> which returns the full string into the first input. I also have the possibility to transform the separator <code>|</code> into <code>,</code> by using <code>var res = str.split("|");</code> but that doesn't really help my case.</p>