title: Javascript - Adjust price when changing quantity
body: <p>I have a form to add product to basket where the user need to select quantity. I'm trying to adjust the price when quantity is modified. Here's my code:</p>
  
  <pre><code>  &lt;script&gt;
    function increaseValue() {
      var value = parseInt(document.getElementById('quantity').value, 10);
      value = isNaN(value) ? 0 : value;
      value++;
      document.getElementById('quantity').value = value;
    }
  
    function decreaseValue() {
      var value = parseInt(document.getElementById('quantity').value, 10);
      value = isNaN(value) ? 0 : value;
      value &lt; 1 ? value = 1 : '';
      value--;
      document.getElementById('quantity').value = value;
    }
    &lt;/script&gt;
  
    &lt;div class="quantity-container"&gt;
    &lt;span&gt;1&lt;/span&gt; 
   &lt;div class="value-button" id="decrease" onclick="decreaseValue()" value="Decrease Value"&gt;-&lt;/div&gt; 
  &lt;input type="number" id="quantity" name="quantity" value="1" /&gt;
  &lt;div class="value-button" id="increase" onclick="increaseValue()" value="Increase Value"&gt;+&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I need to adjust the price for the following scenarios:</p>
  
  <ul>
  <li>If quantity is increased using the 'increase' button</li>
  <li>If quantity is decreased (but prevent zero quantity with $0.00 price)</li>
  <li>If quantity is updated using the quantity text field</li>
  </ul>
  
  <p>The problem is that the price is displayed using html between the numbers so i'm confused how to update the price. I assume I will have to use RegEx? I can't just hardcode the base price ($15.49 in this example) because the price is never the same (the prices come from SQL DB)</p>
  
  <pre><code>&lt;div id="product-price"&gt;
  $15&lt;sup&gt;.49&lt;/sup&gt;
  &lt;/div&gt;
  </code></pre>