title: jQuery select onChange update input field value
body: <p>I have multiple sets of <code>select</code> and <code>input</code>s in one form and I need to update each input based on the selected value. Update the price in the input field based on the select dropdown. </p>
  
  <p>The drop-down carries a value and a data attribute. The value is the quantity, and the data-attr is the price.</p>
  
  <p>So when you select <code>&lt;1&gt;</code> from the drop-down, the input will change to <code>&lt;1&gt; *</code> its data-attribute.</p>
  
  <p>I don't want to use ID's or classes or names to get current onChange.</p>
  
  <p>// jQuery onChange this particular {select_drop_down}</p>
  
  <pre><code>&lt;select class="select"&gt;
      &lt;option value="1" data-price="2.99"&gt;1&lt;/option&gt;
      &lt;option value="2" data-price="2.99"&gt;2&lt;/option&gt;
      &lt;option value="3" data-price="2.99"&gt;3&lt;/option&gt;
      &lt;option value="4" data-price="2.99"&gt;4&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  
  
  <p>// update this input's value to the selected:index * data-price.
  // new value: if option value=2 is selected, change input[type=text] to the new value.</p>
  
  <pre><code>&lt;input type="text" value="2.99"&gt;
  </code></pre>
  
  <p>// same goes for the next {select_drop_down}</p>
  
  <pre><code>&lt;select class="select"&gt;
      &lt;option value="1" data-price="1.99"&gt;1&lt;/option&gt;
      &lt;option value="2" data-price="1.99"&gt;2&lt;/option&gt;
      &lt;option value="3" data-price="1.99"&gt;3&lt;/option&gt;
      &lt;option value="4" data-price="1.99"&gt;4&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  
  
  <pre><code>&lt;input type="text" value="1.99"&gt;
  </code></pre>
  
  <p>So this is what I have so far:</p>
  
  <pre><code>$(".select").change(function () {
      newPrice = 2.99; // I NEED HERE THE CURRENT data-price value;
      $(".one option:selected").each(function () {
          Price = newPrice*$(".unit").val();
      });
      $(this).nextAll('input').first().focus().val(Price.toFixed(2))
  });
  </code></pre>
  
  <p>this works but only for the first drop-down, not the second.</p>