ssss05
ssss05

Reputation: 717

Jquery : multiply two text fields and update into 3rd text field

here i have 3 text fields consider as a1,a2 & a3, now i need to do multiply the values of a1 * a2 and update the answer in to third field. how can i do this with jquery ? do we have any update functions in jquery ?

Upvotes: 1

Views: 13631

Answers (1)

m.t.bennett
m.t.bennett

Reputation: 1320

assuming a1, a2 & a3 are the id's of the elements like so

<input id="a1" type="text" value="10" />
<input id="a2" type="text" value="20" />
<input id="a3" type="text" value="" />

then all you have to do is add this to the page

$(document).ready(function(){
    $('#a1').keyup(calculate);
    $('#a2').keyup(calculate);
});
function calculate(e)
{
    $('#a3').val($('#a1').val() * $('#a2').val());
}

Upvotes: 8

Related Questions