1

Can someone help me?

I need to know how to send the form checkout/cart/updatePost when clicking on a checkbox. It should include an input field hidden or similar with the name=udpate_cart_action and a value.

When we pulse on:

Update Shopping Cart button

<button type="submit"
    name="update_cart_action"
    data-cart-item-update=""
    value="update_qty"
    title="<?php echo $block->escapeHtml(__('Update Shopping Cart')); ?>" class="action update">
     <span>
          <?php /* @escapeNotVerified */ echo __('Update Shopping Cart'); ?>
     </span>
</button>

We send a param in the request object with the name and value.

But I don't if I must to send this name and value with the checkbox or in the JavaScript...

I have this input type checkbox foreach item

<input id="item_<?php echo $block->escapeHtml($itemId) ?>" name="item[check][<?php echo $block->escapeHtml($itemId) ?>]"  type="checkbox" class="check_item" value="<?php echo $block->escapeHtml($itemId) ?>"

And this code javascript:

<script type="text/javascript">
    $(document).ready(function() {
        $(".check_item").on("change", ":checkbox", function() {
            console.log("check");
        });
    });
</script>

But when I pulse on checkbox and it's status change nothing happens :-(

UPDATE

Thanks, Philipp Sander your answer was correct. The problem was to add

require(['jquery'], function ($){ //code ]);

<script type="text/javascript">
    require(['jquery'], function ($) {

        $(".check_item").change(function() {
            if(this.checked) {
                $("#update_baa").click();
            } else {

                $("#update_baa").click();
            }
        });

    });

</script>

Thanks!!

1 Answer 1

0
$(".check_item").change(function() {
    if(this.checked) {
        //Do stuff
    }
});
3
  • Thanks Philipp but not work. In Safari debug console I have this error "TypeError: $ is not a function. (In '$(".check_item")', '$' is undefined)"
    – willy
    Sep 18, 2017 at 15:54
  • I change $ to jQuery and do not work neither
    – willy
    Sep 18, 2017 at 15:55
  • well there you have it Sep 19, 2017 at 7:08

Your Answer

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

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