title: Get value from select option by searching/filtering partial option text and output value as jQuery variable
body: <p>I have a selectbox on a page which looks like this:</p>
  <pre><code>&lt;select id=&quot;mySelect&quot; autocomplete=&quot;off&quot; class=&quot;inputbox input-large&quot;&gt;
   &lt;option value=&quot;&quot;&gt;- Select option -&lt;/option&gt;
   &lt;option value=&quot;1&quot;&gt;Car&lt;/option&gt;
   &lt;option value=&quot;12&quot;&gt;- Plane&lt;/option&gt;
   &lt;option value=&quot;34&quot;&gt;- - Train&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  <p>On the same page I also have a input like this:</p>
  <pre><code>&lt;input type=&quot;text&quot; id=&quot;myInput&quot; name=&quot;myInput&quot; value=&quot;Train&quot;&gt;
  </code></pre>
  <p>Now I need to return the value <code>34</code>. The selectbox option does not have to be selected I just need to have the number that is within the value field. So if the input would read <code>Plane</code> it should return <code>12</code>. Furthermore I would need this value to be a variable so I can use it further down the line in jQuery.</p>
  <p>I have been trying to get this now for over an hour but with most examples on the net it is always about making the option selected and I simply have not found a example on returning the value.</p>
  <p>What I have so far is not even half of what I need but I include it so that everyone can see that I am trying.</p>
  <pre><code>  $str = $('#myInput').val();
  
    var exists = false;
    $(&quot;#mySelect option&quot;).filter(function() {
        return $(this).text().replace(/-/g,&quot;&quot;).trim() == $str;
        var exists = true;
    });
    console.log(exists);
  </code></pre>
  <p>For everyone who is willing to put down a code example please start from scratch as the above is probably wrong in a hundred different ways ;-)</p>