norbidrak
norbidrak

Reputation: 473

Jquery change function inside click function not working properly

I have selects with some values, and i want to remember value by clicking one of them and after change do something with this.

 $("select[id^='zmieniaj']").click(function() {
      var poprz=$(this).val();
      $("select[id^='zmieniaj']").change(function(){
      ...
});
});

So im remembering clicked value in variable and i refer to it in change function. It works good when i click only once on select and made change in the same step. If i click few times it does not trigger change function imimmediately, but it remembers how many times i clicked and when i made change it acts crazy by making up for previous clicks.

How to do that, if CONDITION A-click and CONDITION B-change is made only then, and only once do what is in change function ??

Upvotes: 0

Views: 1089

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388406

Try something like

$("select[id^='zmieniaj']").focus(function () {
    var $this = $(this);
    $this.data('fvalue', $this.val());
}).change(function () {
    var $this = $(this),
        cval = $this.val(),
        pval = $this.data('fvalue');
});

Upvotes: 1

Related Questions