skip to Main Content

I want to get input text value in checkout page.

I have tried to apply jquery in checkout page but it didn’t work it. I have also worked with pure javascript but it also didn’t work.

Jquery not working because checkout page working only knockout js

<script type="text/javascript">
    require([ 'jquery', 'jquery/ui'], function($){ 
        jQuery(window).load(function(){
            jQuery("#shipping-new-address-form input[name='vat_id']").keyup(function(e) {
                alert("test");
            });
        }); 
    });

</script>

This code is working fine on console.

Please help me and solve this issue

Thanks in advance.

2

Answers


  1. Magento 2 works with requireJS library, so you need to use “require”/”define” function to receive the jquery.

    I think that you want to change the shipping behavior, so, you can do a fallback of shipping.js from Magento_Checkout module and add your code there.

    your-theme/Magento_Checkout/web/js/view/shipping.js
    
    Login or Signup to reply.
  2. Hi please try the below code and it should work as i am already using something like this and it is working fine.

    <script type="text/javascript">
        require(['jquery', 'jquery/ui'], function($){
            jQuery(document).on('keyup', '#shipping-new-address-form input[name="vat_id"]', function(e) {
                            alert("test");
            });
        });
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search