title: AJAX form executed by onblur OR change event
body: <p>I have a form where the user will enter a number into a text field.  Then, select another number from a dropdown menu.  I want the AJAX to execute each time they go from field to field.  This is so that it does a calculation in real-time.  </p>
  
  <p>I would imagine the text field would be using "onblur" and the dropdown using "change" or "onchange"...  but how do I write the script to do EITHER depending on which field they are currently on?  Can you set it to do both?</p>
  
  <p>EDIT:  New attempt with new variable labels.  </p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
          function postData(){
              var widthX = $('#width_str').val();
              var heightX = $('#height_str').val();
              var prodidX = $('#prodid').val();
              var roomX = $('#room_str').val();
  
              $.post('db_query.php',{widthX:widthX, heightX:heightX, prodidX:prodidX, roomX:roomX},   
                  function(data){
                  $("#search_results").html(data);
              });
          }
  
          $(function() {
              $("#lets_search").bind('submit',function() {postData()});
              $("#room_str").bind('change', function() {postData()});
              $("#width_str").bind('change', function() {postData()});
              $("#height_str").bind('change',function() {postData()});
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>Part of the form here....</p>
  
  <pre><code>         &lt;form id="lets_search" action="" style="width:400px;margin:0 auto;text-align:left;"&gt;
              &lt;input type="hidden" value="1" value="&lt;?php echo stripslashes($_GET['prodid']); ?&gt;" name="prodid" id="prodid"&gt;
  
              room name:
              &lt;select name="room_str" id="room_str"&gt;
                  &lt;option value="Dining"&gt;Dining&lt;/option&gt;
                  &lt;option value="Bathroom"&gt;Bathroom&lt;/option&gt;
                  &lt;option value="Kitchen"&gt;Kitchen&lt;/option&gt;
              &lt;/select&gt;
              height:
              &lt;select name="height_str" id="height_str"&gt;
                  &lt;option value="30"&gt;30"&lt;/option&gt;
                  &lt;option value="31"&gt;31"&lt;/option&gt;
                  &lt;option value="32"&gt;32"&lt;/option&gt;
                  &lt;option value="33"&gt;33"&lt;/option&gt;
                  &lt;option value="34"&gt;34"&lt;/option&gt;
                  &lt;option value="35"&gt;35"&lt;/option&gt;
                  &lt;option value="36"&gt;36"&lt;/option&gt;
                  &lt;option value="37"&gt;37"&lt;/option&gt;
              &lt;/select&gt;
              &lt;br&gt;
              width:
              &lt;select name="width_str" id="width_str"&gt;
                  &lt;option value="30"&gt;30"&lt;/option&gt;
                  &lt;option value="31"&gt;31"&lt;/option&gt;
                  &lt;option value="32"&gt;32"&lt;/option&gt;
                  &lt;option value="33"&gt;33"&lt;/option&gt;
                  &lt;option value="34"&gt;34"&lt;/option&gt;
                  &lt;option value="35"&gt;35"&lt;/option&gt;
                  &lt;option value="36"&gt;36"&lt;/option&gt;
                  &lt;option value="37"&gt;37"&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type="submit" value="send" name="send" id="send"&gt;
           &lt;/form&gt;
  </code></pre>
  
  <p>The php page that processes the data...</p>
  
  <pre><code>&lt;?php
  include('db_pbconnection.php');
  
  $tax = .06;
  $tax2 = 1.06;
  $grandtotal = 50;   
  
  $query = mysql_query(" SELECT * FROM price_dimensions WHERE prodid = '".$_POST['prodidX']."' AND height &gt;= '".$_POST['heightX']."' AND width &gt;= '".$_POST['widthX']."' ORDER BY height ASC, width ASC LIMIT 1 ");
  echo '&lt;div&gt;';
  while ($data = mysql_fetch_array($query)) {
      echo '
      &lt;div style="background-color:pink;"&gt;
          &lt;div style="clear:both; font-size:18px;"&gt;height: '.$data["height"].'&lt;/div&gt;&lt;br&gt;
          &lt;div style="clear:both; font-size:18px;"&gt;width: '.$data["width"].'&lt;/div&gt;
          &lt;div style="clear:both; font-size:18px;"&gt;unit price: '.$data["price"].'&lt;/div&gt;
          &lt;div style="clear:both; font-size:18px;"&gt;tax: '.(($data["price"])*($tax)).'&lt;/div&gt;
          &lt;div style="clear:both; font-size:18px;"&gt;grand total:'.(($data["price"])*($tax2)).'&lt;/div&gt;
      &lt;/div&gt;';
  }
  echo '&lt;/div&gt;';
  ?&gt;
  </code></pre>