how do i calculate 2 input fields and put results in 3rd input field

user2489811 picture user2489811 · Aug 18, 2013 · Viewed 18.3k times · Source

i want to have a form whereby i can add a value into the first text field, multiply that by a second hidden field, and display results in a 3rd text field. I want it so as soon as you add a value to the first field it shows the result in the 3rd field, eg on key up.

<label>Qty:</label>
<input name="qty" id="qty" type="text" />
<input name="price" id="price" type="hidden" value="30" /><br />

<label>Total:</label>
<input name="total" id="total" type="text" />

Any help would be great as im new to jquery.

Answer

Akhil5 picture Akhil5 · Aug 18, 2013
$("#qty").keyup(function(){
   total = $("#qty").val()* $("#price").val();
   $("#total").val(total);
});