I tried to call a function from JavaScript file to define a base price for an item.
For example, if you try to buy 500 Credits, it will call a function called "getPrice()" like this:
<div class="panelButton">
<div class="header">Credits: 500</div>
<div class="body">
<p>Buy Credits 500 / <script type='text/javascript' src="scripts/price.js">getPrice(500);</script>€</p>
</div>
</div>
If the base price for one credit is like 0.01€, it will display the correct amount for buying 500 Credits from the .js file. This is the .js file:
var baseCreditPrice = 0.05;
function getPrice(factor) {
return baseCreditPrice * factor;
}
How is that called? Because the text won't change at all. If I use getPrice(500); it will make the text display a number that is 0.05 * 500.
AngularJSif you want to write things up in this manner. Otherwise, you could achieve this by giving a target to your script<p>tag and having the code run on page load. I don't know to the extent of what you want this code to be (i.e. will you have more of these<p>on one page? But I will create a quick example of what I mean.