developer_cz Developer From Czech Republic Member since Apr 2018 developer_cz Oct 15 2020 01:16 PM Selecting/changing shipping method in checkout - it is possible to catch via JS/jQuery (any event)? I need to detect selected shipping method/module and trigger another event via JS/jQuery. How best to do it? Thanks for help.
tim Founder From Sweden Member since May 2013 tim Oct 15 2020 03:51 PM Use regular jQuery Events: alert('You clicked option: ' + $(this).val()); });``` This willl not work as the content is refreshed by ajax and the set events are lost upon that refresh: ```$('input[name="shipping[option_id]"]').change(function(){ alert('You clicked option: ' + $(this).val()); });```
developer_cz Developer From Czech Republic Member since Apr 2018 developer_cz Oct 15 2020 04:36 PM I've tried that, but it doesn't work in Google Chrome or in any other browser. I found "There's no reliable cross-browser event that gets fired when the content of a DIV (as opposed to a form element, say) changes.".
tim Founder From Sweden Member since May 2013 tim Oct 15 2020 08:05 PM You are right, "click" as an event works but not change. I wonder why.
developer_cz Developer From Czech Republic Member since Apr 2018 developer_cz Oct 15 2020 09:32 PM I spent several hours doing this, but I could not find a solution. Manually triggering a change event on the input (shipping[option_id]) is probably the only one solution.
tim Founder From Sweden Member since May 2013 tim Oct 16 2020 01:34 AM Click should do if you check the check state between the clicks. Still, I'm very surprised. The radio buttons are hidden, but the label wrapper should delegate the onchange event. Try triggering the event like this: In includes/templates/default.catalog/pages/checkout.inc.php Find $(this).find('input[name="shipping[option_id]"]').prop('checked', true); Replace with $(this).find('input[name="shipping[option_id]"]').prop('checked', true).trigger('change');
developer_cz Developer From Czech Republic Member since Apr 2018 developer_cz Oct 16 2020 09:59 AM Thanks, that's the solution. Great. One last step - can you take a look at [url=https://www.litecart.net/en/forums/2/general-discussions/1373/how-to-pass-something-from-shipping-module-to-order#1386][/url][url=https://www.litecart.net/en/forums/2/general-discussions/1373/how-to-pass-something-from-shipping-module-to-order#1386]this topic[/url]?