title: How to use jQuery to compare two values?
body: <p>I'm trying to use jQuery to compare two values in an html table, and alert the user if quantity > inventory.</p>
  
  <p>I want to select values in the current row :</p>
  
  <h2>JS</h2>
  
  <pre><code>    $('.item_quantity').change(function(){       
          var $this=$(this);        
          var quantity=$this.val();        
          // var inventory=$this.next('.item_inventory, td').text();
           var inventory=$(this).next('td, .item_inventory').text();
  
          console.log('quantity: ', quantity, 'inventory: ', inventory);
          if (quantity &gt; inventory) {
            alert('Your order quantity ' + quantity + ' is greater than ' + inventory + ' inventory');
          }            
      });               
  });
  </code></pre>
  
  <h2>HTML</h2>
  
  <pre><code>&lt;table &gt;    
    &lt;tr&gt;         
      &lt;td&gt;&lt;form method=""&gt;&lt;input class="item_quantity" type="text"  data-prodid="249" value=""/&gt;&lt;/form&gt;&lt;/td&gt;
      &lt;td  class="item_inventory"&gt;10&lt;/td&gt;
      &lt;td&gt;Product 1&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;         
      &lt;td&gt;&lt;form method=""&gt;&lt;input class="item_quantity" type="text" data-prodid="2" value=""/&gt;&lt;/form&gt;&lt;/td&gt;
      &lt;td class="item_inventory"&gt;7&lt;/td&gt;
      &lt;td&gt;Product 2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>