I've created a JavaScript script function that holds cart items for ordering food. This function takes two parameters: ID and price.
Here is a snippet of my script file:
<script>
function addtocart(mitem, mprice) {
var price = String(mprice)
var mobj = { String(mitem): price }
var storeobj = JSON.stringify(mobj)
localStorage.setItem('cart', storeobj)
}
</script>
My button looks like this:
<p style="position: absolute; bottom: 0px"><button class="button" style="width: 200px" onclick="addtocart( '{{M.Menu_Item}}', '{{M.Menu_ItemPrice}}' )" >Add to Cart</button>
However, when I click on the button in Chrome developer console, it says that the addtocart function is not defined.
I've looked into using onclick listeners, but I need to pass different parameters for each button click. What could I be doing wrong?