Skip to content
Advertisement

How to set amount of an item dynamically in javascript

I am trying to integrate a payment gateway on my website. Here is my code

products.php

JavaScript

main.js

JavaScript

Now, the problem is that there are many products with different prices; but here I can only put a static amount (50000) which applies to all products when the action button is clicked. Is there any way I can dynamically get the price of products and set it in my function in case of a product that has a different price?

I tried this but it doesn’t work

JavaScript

Advertisement

Answer

Pass the element as argument to a “new” function to handle the price before calling your widget. It can be done using this between the parenthesis of the onclick function call. Then you will be able to retreive the price from the amount-price attribute.

JavaScript

JavaScript

If amount-price includes a currentcy symbol, you have to remove it.

Advertisement