Author Topic: Custom Javascript on product-variation pages not executing  (Read 443 times)

mediakrt

  • Beginner
  • *
  • Posts: 8
  • A beginner
Custom Javascript on product-variation pages not executing
« 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

Jörgen

  • Global Moderator
  • Full Member
  • *
  • Posts: 2314
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Custom Javascript on product-variation pages not executing
« Reply #1 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

Jörgen @ Kreativ Fotografi
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9031
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: Custom Javascript on product-variation pages not executing
« Reply #2 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3975
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Custom Javascript on product-variation pages not executing
« Reply #3 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...