Jquery.bind prevents page loading from starting

I have a jquery function that associates a select field in a form with multiple actions. It communicates with both the change and the keyboard, so mouse clicks and keyboards are captured.

$(document).ready(function(){
  $('#user_id').bind('change keyup',function () {
    calculateAmounts();
  }).change();
});

It works great.

However, in addition to launching the change and keyup functions, the calculateAmounts () function is also called the first time the page loads. I would like this code not to run the first time the page loads.

0
source share
2 answers

, .change() $('# user_id'), change/keyup. .change(), :

$(document).ready(function(){
  $('#user_id').bind('change keyup',function () {
    calculateAmounts();
  });
});
+2

( , #user_id - )

$(document).ready(function(){
  var yourVAL = $("#user_id").val();
  $('#user_id').bind('change keyup',function () {
    if($("#user_id").val() != yourVAL){
        calculateAmounts();
    } 
  }).change();
});
0

All Articles