title: jQuery .change value for multiple items matched on dynamically generated names/ids
body: <p>I have a dynamically generated collection of multiple select / input pairs, with generated IDs.</p>
  
  <p><em>Stripped down:</em></p>
  
  <pre><code>&lt;?php foreach ($products as $product) { ?&gt;
    &lt;select id="option_&lt;?php echo $matching_id; ?&gt;"&gt;
      &lt;?php foreach ($options as $option) { ?&gt;
         &lt;option title="&lt;?php echo $inputvalue ?&gt;"&gt;&lt;/option&gt;
      &lt;?php } ?&gt;
    &lt;/select&gt;
    &lt;input id="update_&lt;?php echo $matching_id; ?&gt;" type="text" value="" /&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>I have this jQuery to update the input field with the title attribute (have to use title since the value attribute is needed for something else) of the selected option:</p>
  
  <pre><code>$(document).ready(function () {
      $('select').change(function() {
      $('input').val($(this).find("option:selected").attr("title"));
      });
  });
  </code></pre>
  
  <p>Of course this is wrong. It updates ALL the input fields with the same value, regardless of which select box is changed.</p>
  
  <p>I need only the input box with the matching ID number to change. The $matching_id variable is always a number, if that's relevant.</p>
  
  <p>Can some helpful person point me in the right direction?</p>