cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect postcode change on Cart

How to detect postcode change on Cart

I would like to know how to detect postcode change on cart page.

This code won't work.

 

$(".input-text[name=postcode]").on("change", function(){

console.log('detected');

});
3 REPLIES 3

Re: How to detect postcode change on Cart

Hello,

 

Magento 2 using KO for a quote so you can easily get current shipping postcode easily from js

 

require(['jquery','Magento_Checkout/js/model/quote'], function($,quote){ 
            console.log(quote.shippingAddress().postcode)
})

If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to detect postcode change on Cart

I'm sorry but my question was how to detect When the postcode is changed.

 

Also the code is getting an error.

 

Uncaught TypeError: Cannot read property 'postcode' of null

Re: How to detect postcode change on Cart

Try with below code in js and let me know,

$( document ).on( "change",'input[name="postcode"]', function() {
	console.log(getPostcode());
});
If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial