0

I made a function loadcomputers() that otomatically update a select list with id=computer loadcomputers() gets the filter form the input field with id="rating" input field with id="rating" is automatically filled out by another function rate(item) Problem is when input field with id="rating" is automatically filled out, the function loadcomputers() dosn't load but if I type manually it works

 <div>
    <ul>
      <li>
        <input class="ccheckbx" type="checkbox" name="application[]" value="1" onClick="rate(this);"  />Office              
      </li>
      <li>
        <input class="ccheckbx" type="checkbox" name="application[]" value="2" onClick="rate(this);"  />Game 
      </li>     
    </ul>

      <input type="text" id="rating" oncchange="loadcomputers()"/>
      <select name="computer" id="computer"></select>
</div>
--------------------------------------------------

  var total = 0;

function rate(item){
    if(item.checked){
       total+= parseInt(item.value);
    }else{
       total-= parseInt(item.value);
    }
    //alert(total);
    document.getElementById('rating').value = total + "";
}
-------------------------------------------

function loadcomputers() {
    $val = $('#rating').val();
    $.post('http://exemple1.com/action/subs/pcdrop2.php', {
    rating: $val
    }, function (data) {
    $('#computer').html(data);
});
}

1 Answers1

0

you might be able to trigger the event yourself by using

$('#rating').trigger('change');

in loadComputers()

btw: there is a typo, it's supposed to be onchange, you have oncchange

Martin-Mueller
  • 141
  • 1
  • 10
  • Thank you I have tried this but it is not working. `function loadcomputers() { $val = $('#rating').val(); $.post('http://onlinepcdoc.com/action/subs/pcdrop2.php', { rating: $val }, function (data) { $('#computer').html(data); $('#rating').trigger('change'); }); }` – user3691344 Jul 17 '14 at 20:48
  • I added `$('#rating').trigger('change');` on rate(item) instate and it worked. Thank you. – user3691344 Jul 17 '14 at 23:19