0

There is a drop-down value from 1 to 10+ on Cart page. Whenever I select 1 to 9 option from drop-down, Cart is updated onchange event.

When I select 10+ from the drop-down, drop-down should be hidden.and Textbox should be displayed to enter the value. Whenever I select 10+, Cart should not be updated.

<div class="gravdept-select gravdept-select--compact">
      <select class="qty" name="cart[<?php echo $_item->getId() ?>][qty]" id="cart[<?php echo $_item->getQty(); ?>][qty]" value="<?php echo $this->getQty(); ?>" onchange="this.form.submit()">
          <?php
               $total = 10;
                   for ($x=1; $x<$total; $x++) {?>
                         <option value="<?php echo $x?>" <?php echo ($x == $this->getQty())? "selected=selected": ""; ?>><?php echo $x?></option>
                          <?php
                             }
                             if($x == 10)
                             {
                                 echo '<option value="10+">10+</option>';
                             }
                            ?>
       </select>

Above code, I have written in checkout/cart/item/default.phtml.

1 Answer 1

0
<script type="text/javascript">
    showTextBox(obj) {
        if(obj.value < 9) {
            $('extra_qty_box').hide();
            this.form.submit();
        } else {
            $('extra_qty_box').show();
        }
    }
</script>    
<div class="gravdept-select gravdept-select--compact">
      <select class="qty" name="cart[<?php echo $_item->getId() ?>][qty]" id="cart[<?php echo $_item->getQty(); ?>][qty]" value="<?php echo $this->getQty(); ?>" onchange="showTextBox($this)" >
          <?php foreach(range(1,9) as $qty): ?>
            <option value="<?php echo $qty ?>" <?php echo ($qty == $this->getQty()) ? "selected=selected" : ""; ?>><?php echo $qty ?></option>
          <?php endforeach;?>
          <option id="extra_qty_opt" value="10">10+</option>
       </select>
       <div id="extra_qty_box" style="display: none;">
           <input type="text" class="required_entry" name="extra_qty_txt" id="extra_qty_txt" value="0" onkeyup="$('extra_qty_opt').value = this.value">
           <button name="extra_qty_btn" class="button" onclick="this.form.submit()"><span><span><span>Update</span></span></span></button>
       </div>

Replace your code with above code and see if it's works

2
  • I am not getting this. Kindly elaborate.
    – gt06
    Sep 17, 2017 at 6:14
  • @gt06: check updated code. replace code with your existing code. Sep 23, 2017 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.