Brian Moreno
Brian Moreno

Reputation: 1027

jQuery Click Event Issue - Framework7

So I have a couple of problems. The first one... I have 2 pages, a products.html page and a search.html page. The products.html page runs some Ajax in the .onPageAfterAnimation(); to get the products from the database and display them. The returned HTML contains a part where the user can increase and decrease a number value inside a textbox.

The button to

The button to increase or decrease the value by 1 initially works when I open the products.html page, however, when I go into the search.html and go back to the products.html page using my Android's back button (I have pushState = true) and press the increase/decrease button it increases/decreases by 2. If I try to do the same thing again it increases/decreases by 3 and so on…

This is my inc

This is my increase/decrease code in my products.html page:

myApp.onPageAfterAnimation('catalogs', function (page) {

  //Increse/decrease product quantity
  $(“.promo-screen-content”).on(“click”, “.addToCartBtn”, function(){
    var productid = $(this).attr(“data-productId”),
        currentvalue = parseInt($('#txtQuantity' + productid).val());

    $('#txtQuantity' + productid).val((currentvalue + 1).toString());
  });

  $(“.promo-screen-content”).on(“click”, “.removeFromCartBtn”, function(){
    var productid = $(this).attr(“data-productId”),
        currentvalue = parseInt($('#txtQuantity' + productid).val());

    if(currentvalue > 1){
        $('#txtQuantity' + productid).val((current_value – 1).toString());
    }
  });

});

Anyone know why this is happening and how to fix it?

My second problem is a little bit different. When ever I click a button it takes that click and performs the process 3 or 4 times. So, for example, if I show a notification when it is clicked it shows that notification 3 or 4 times.

I don't know if these are common or know issues that people have came across. Any help is greatly appreciated!

Upvotes: 0

Views: 607

Answers (1)

Brian Moreno
Brian Moreno

Reputation: 1027

I was putting my code inside the wrong page callback. I had to put it inside the .onPageInit(); callback.

Upvotes: 1

Related Questions