I have two buttons and if I click on some button I need to change value in input text and change total price (product price * value of button - 2 or 4 Qty).
I know that it's simple but I'm not good in javascript or jQuery. Answer in jsfiddle would be best.
My jsfiddle is here http://jsfiddle.net/J7m7m/1/
My simple code:
Product price: $500
<br>
Total price: $500
<br>
<input type="button" onclick="change()" value="2
Qty">
<input type="button" value="4
Qty">
<br>
Total <input type="text" id="count" value="1">
Try This(Simple javascript):-
Hope this will help you..
using html5 data attribute...
try this
Html
JS
fiddle here
Another simple solution for this case using jQuery. Keep in mind it's not a good practice to use inline javascript.
JsFiddle
I've added IDs to html on the total price and on the buttons. Here is the jQuery.
My Attempt ( JsFiddle)
Javascript
Html
This will work fine for you
And here is the non jQuery answer.
Fiddle: http://jsfiddle.net/J7m7m/7/
HTML slight modification:
EDIT: It is very clear that this is a non-desired way as pointed out below (I had it coming). So in essence, this is how you would do it in plain old javascript. Most people would suggest you to use jQuery (other answer has the jQuery version) for good reason.