title: JS select correct line in select list
body: <p>I am using this JS code to do some magic. Working perfect to get a variabele and remove unwanted text and display the correct text in a <code>text field</code>.</p>
  <p><code>values 2 or 3 or 5 or 7 etc.</code> in <code>&lt;input type=&quot;text&quot; id=&quot;calc_dikte[0][]&quot; name=&quot;calc_dikte[]&quot; value=&quot;&quot;&gt;</code></p>
  <pre><code>function copy_dikte()
  {
      var i;
      var elems = document.getElementsByName('dxf_var_dikte_copy[]');
      var elems_1 = document.getElementsByName('dxf_vars[]');
      var elems_2 = document.getElementsByName('calc_dikte[]');
      var elems_3 = document.getElementsByName('calc_ext[]');
      var l = elems.length;
      var z;
      z=0;
  
      for(i=0; i&lt;l; i++)
      {
          if(elems_3[i].value == 'dxf')
          {
              elems[i].value = document.getElementById('dxf_var_dikte').value;
  
              var elems_1_split_1 = (elems_1[i].value).split(elems[i].value+'=');
              var elems_1_split_2 = (elems_1_split_1[1]).split(',');
  
              if(isNaN(elems_1_split_2[0])) { elems_2[i].value = ''; }
              else { elems_2[i].value = parseFloat(elems_1_split_2[0]); }
          }
      }
  }
  </code></pre>
  <p>So this works, but now the form field has changed from <code>text</code> to <code>select</code> like:</p>
  <pre><code>&lt;select id=&quot;calc_dikte[0][]&quot; name=&quot;calc_dikte[]&quot;&gt;
  &lt;option value=&quot;&quot;&gt;
  &lt;option value=&quot;2|2000&quot;&gt;2&lt;/option&gt;
  &lt;option value=&quot;3|2000&quot;&gt;3&lt;/option&gt;
  &lt;option value=&quot;5|2000&quot;&gt;5&lt;/option&gt;
  &lt;option value=&quot;7|2000&quot;&gt;7&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  <p>Therefore I have changed my JS code (<a href="https://stackoverflow.com/questions/3989324/javascript-set-dropdown-selected-item-based-on-option-text">with some tips from here</a>) to:</p>
  <pre><code>function copy_dikte()
  {
      var i;
      var elems = document.getElementsByName('dxf_var_dikte_copy[]');
      var elems_1 = document.getElementsByName('dxf_vars[]');
      var elems_2 = document.getElementsByName('calc_dikte[]');
      var elems_3 = document.getElementsByName('calc_ext[]');
      var l = elems.length;
      var z;
      z=0;
  
      for(i=0; i&lt;l; i++)
      {
          if(elems_3[i].value == 'dxf')
          {
              elems[i].value = document.getElementById('dxf_var_dikte').value;
  
              var elems_1_split_1 = (elems_1[i].value).split(elems[i].value+'=');
              var elems_1_split_2 = (elems_1_split_1[1]).split(',');
  
              var sel = elems_2[i];
              var val = parseFloat(elems_1_split_2[0]);
  
              for(var m=0, n=sel.options.length; m&lt;n; m++)
              {
                  if(sel.options[i].innerHTML === val)
                  {
                     sel.selectedIndex = m;
                     break;
                  }
              }
          }
      }
  }
  </code></pre>
  <p>But this is not working, no item is selected in the select list, no errors are shown.
  Please help me out change to a working code to have the correct line selected. It should not select on the <code>value</code> but in the text between the <code>&gt;&lt;</code>
  option value=&quot;5|2000&quot;&gt;<strong>5</strong>&lt;/option</p>
  <p>If I check with</p>
  <pre><code>for(var m=0, n=sel.options.length; m&lt;n; m++) {
  alert('sel = '+sel.options[i].innerHTML+'\nval = '+val);
  }
  </code></pre>
  <p>I see that <code>val</code> is correct. But <code>sel </code> is just the number as used in <code>$i</code> so <code>0</code> <code>1</code> <code>2</code></p>