I have three textboxes, when I modify either textbox A or Textbox B Textbox C should change to A*B e.g. If A is 3 and B is 4 C is 12... if i change B to 5 C should automatically change to 15. js fiddle here: http://jsfiddle.net/Lazyboy4ever/mfyh2/
3 Answers
Bind the .change() event handler to inputs A and B, convert their value to a number using parseFloat(), multiply them, and assign the result to C:
$("[name='qty'],[name='b']").change(function () {
var $tr = $(this).closest("tr"),
qty = $tr.find("[name='qty']").val(),
b = $tr.find("[name='b']").val();
var c = parseFloat(qty) * parseFloat(b);
$tr.find("[name='c']").val(c);
});
DEMO.
Comments
****I'll say, please search it but I'm afraid you'll ask "where?". So, please Google it before asking.****
Change this solution to multiply : How to calculate the total value of input boxes using jquery
Comments
Here is another example that might work for your case:
HTML:
<input id="txt1" type="text" /><br />
<input id="txt2" type="text" /><br />
<input id="txt3" type="text" /><br />
Javascript:
$(function(){
$(document).on('blur', '#txt1', function(){
var one = $('#txt1').val();
var two = $('#txt2').val();
var three = $('#txt3').val();
$('#txt3').val(one * two);
});
$(document).on('blur', '#txt2', function(){
var one = $('#txt1').val();
var two = $('#txt2').val();
var three = $('#txt3').val();
$('#txt3').val(one * two);
});
});