title: Best way to trigger jquery with range input
body: <p>I have a problem with my jquery...The function works well with other elements, but not with the range input. I want to calculate a value and I need to access other values for that</p>
  
  <pre><code>&lt;input type="range" name="range" id="range" min="0" max="&lt;?php echo $max_range; ?&gt;" oninput="calc_happy()"&gt;
  &lt;input type="number" name="range" id="ranged" value=""oninput="calc_happy()"&gt;
  &lt;select name="work_value" id="work_value" onchange="calc_happy()"&gt;
    &lt;option value="-1.0"&gt;Low work&lt;/option&gt;
    &lt;option value="-1.2"&gt;Easy work&lt;/option&gt;
    &lt;option value="-1.4"&gt;Normal work&lt;/option&gt;
    &lt;option value="-1.6"&gt;Hard work&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>And here is the Js:</p>
  
  <pre><code>&lt;script&gt;
  function calc_happy(){
      var selected = $('#work_value').val();
      var ranged = $('#range').val();
      var happy = Math.round(selected*ranged);
      var nhappy = &lt;?php echo $happy-$wood_minus;?&gt;+happy;    
  
      $('#w_stats td').eq(7).html(Math.abs(happy));
      $('#w_stats td').eq(5).html(selected);
      //calcul new happy
      $('p4').html(nhappy);
      $('p2').html(happy);
  
      if(nhappy &lt;= 1){
          $('#img').attr("src","../design/images/stats/sad.bmp");
      }
  }
  &lt;/script&gt;
  &lt;script&gt;
      window.onload = function() {
          $('#work_value').val('&lt;?php echo $wood_w; ?&gt;');
          $('#range').val('&lt;?php echo $wood_minus/$wood_w; ?&gt;' );
          $('#ranged').val('&lt;?php echo $wood_minus/$wood_w; ?&gt;' );
      }
  &lt;/script&gt;
  &lt;script&gt;
      function putvalue(){
          $('#ranged').val($('#range').val());
      }
      function putvalue2(){
          $('#range').val($('#ranged').val());
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The script is working well for the select input, but not for the other triggers... Please, mind my poor coding, I appreciate any advice and notice it for future. Thanks!
  Edit: and the piece of code</p>
  
  <pre><code>   window.onload = function() {
          $('#work_value').val('&lt;?php echo $wood_w; ?&gt;');
  }
  </code></pre>
  
  <p>receive values from db which match with option values, but sometimes is working, sometimes not...even with multiple refreshes...</p>