Aleks Kpur Aleks Kpur - 5 months ago 14
jQuery Question

HTML/Javascript - Button onClick calling function with variables

So I have an online store, I have an button which calls a function called

purchase()
, but in Javascript this function has
purchase(name, amount)
. So, you can put name easily, in the onclick function
onclick="purchase('milk')
, but my problem is how I could put the amount? Amount is being chosen from the
<select>
element.

I created somekind of JSFiddle as well, so you can take a look: https://jsfiddle.net/w2bk9hw8/

Answer

Using jquery you could do this;

 <button class="button" onclick="payment('milk', $('select').val())">$1.85</button>