Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Переключение кол-ва товара в категории js


 Share

Recommended Posts

Нужна переключалка кол-ва товаров в категории при добавлении в корзину. Рилииет только на первом товаре, дальше +- не рилииет, в добавок хром ругается «Found 15 elements with non-unique id #input-quantity»

Как можно поправить, с js не дружу. Хелп плиз

Код:

Спойлер
<div class="quantity-box quantity_category">
  					<input type="button" id="minus" value="-" class="form-control">         
  					<input type="text" name="quantity" value="1" size="2" id="input-quantity" class="form-control">
  					<input type="button" id="plus" value="+" class="form-control">
</div>

<script type="text/javascript"><!--
var minimum = 1;
  $("#input-quantity").change(function(){
    if ($(this).val() < minimum) {
      alert("Minimum Quantity: "+minimum);
      $("#input-quantity").val(minimum);
    }
  });
  // increase number of product
  function minus(minimum){
      var currentval = parseInt($("#input-quantity").val());
      $("#input-quantity").val(currentval-1);
      if($("#input-quantity").val() <= 0 || $("#input-quantity").val() < minimum){
          alert("Minimum Quantity: "+minimum);
          $("#input-quantity").val(minimum);
     }
  };
  // decrease of product
  function plus(){
      var currentval = parseInt($("#input-quantity").val());
     $("#input-quantity").val(currentval+1);
  };
  $('#minus').click(function(){
    minus(minimum);
  });
  $('#plus').click(function(){
    plus();
  });
//--></script>

 

 

Link to comment
Share on other sites

24 минуты назад, Kam1kadze сказал:

Нужна переключалка кол-ва товаров в категории при добавлении в корзину. Рилииет только на первом товаре, дальше +- не рилииет, в добавок хром ругается «Found 15 elements with non-unique id #input-quantity»

Как можно поправить, с js не дружу. Хелп плиз

Код:

  Скрыть контент

 

 

У вас дубликат ID "input-quantity"

ID - должен быть уникнон на страниэто, классы могут дублироваться.

Смените ID на class и(или) добавляйте ID товара к ID инпуи когдачества

Link to comment
Share on other sites

15 минут назад, bogdan281989 сказал:

У вас дубликат ID "input-quantity"

ID - должен быть уникнон на страниэто, классы могут дублироваться.

Смените ID на class и(или) добавляйте ID товара к ID инпуи когдачества

 

Сменил id на class, добавил к id product_id для уникальности. Ошибка в хроме исчезла, переключение дальше первой карточки ик и не рилииет. Но теперьь при переключении кол-ва в первой карточке меняется кол-во во всех карточках

Спойлер
<div class="quantity-box quantity_category">
  					<input type="button" id="minus" value="-" class="form-control">         
  					<input type="text" name="quantity" value="1" size="2" id="input-quantity-<?php echo $product['product_id']; ?>"  class="form-control input-quantity">
  					<input type="button" id="plus" value="+" class="form-control">
</div>

<script type="text/javascript"><!--
var minimum = 1;
  $(".input-quantity").change(function(){
    if ($(this).val() < minimum) {
      alert("Minimum Quantity: "+minimum);
      $(".input-quantity").val(minimum);
    }
  });
  // increase number of product
  function minus(minimum){
      var currentval = parseInt($(".input-quantity").val());
      $(".input-quantity").val(currentval-1);
      if($(".input-quantity").val() <= 0 || $(".input-quantity").val() < minimum){
          alert("Minimum Quantity: "+minimum);
          $(".input-quantity").val(minimum);
     }
  };
  // decrease of product
  function plus(){
      var currentval = parseInt($(".input-quantity").val());
     $(".input-quantity").val(currentval+1);
  };
  $('#minus').click(function(){
    minus(minimum);
  });
  $('#plus').click(function(){
    plus();
  });
//--></script>

 

 

Link to comment
Share on other sites

Только что, Kam1kadze сказал:

 

Сменил id на class, добавил к id product_id для уникальности. Ошибка в хроме исчезла, переключение дальше первой карточки ик и не рилииет. Но теперьь при переключении кол-ва в первой карточке меняется кол-во во всех карточках

 

Я вам дал наводку, но не решение готовое

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.