VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: mediakrt on February 08, 2019, 10:13:44 AM

Title: Custom Javascript on product-variation pages not executing
Post by: mediakrt on February 08, 2019, 10:13:44 AM
Hello dear Virtuemart-Community

I use a custom javascript to make manipulations on the product page. The javascript is loaded in the footer of the template and is working as expected. I only have one problem. On product pages where i can select different product options by a select field. The script is not loading/working/executing after i select a variation and the variation-information is loaded into the site by AJAX and the url of the page changes.

How is it possible, that my custom js is also working on all product-variantions when i change the variation via select field.

Thank you so much for your help and best regards!
Pascal
Title: Re: Custom Javascript on product-variation pages not executing
Post by: Jörgen on February 08, 2019, 11:10:36 AM
This should probably be handled by the VM javascript handler:
https://docs.virtuemart.net/tutorials/development/196-the-vm-javascript-handler.html (https://docs.virtuemart.net/tutorials/development/196-the-vm-javascript-handler.html)

Jörgen @ Kreativ Fotografi
Title: Re: Custom Javascript on product-variation pages not executing
Post by: GJC Web Design on February 08, 2019, 15:32:18 PM
that and make sure the JS is reloaded/reattached within the div that is renewed by the ajax
Title: Re: Custom Javascript on product-variation pages not executing
Post by: Studio 42 on February 09, 2019, 11:52:54 AM
You have the solution to use
jQuery('mycontainer').on('click','mybutton','function(){
//code to execute
});
mycontainer should be outside the main product container or the product container for eg.
In this case you never loose the binded click
and you can load the function in an external file and check if object exist to not load again the function...