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/
Asked
Active
Viewed 241 times
-2
-
Your code is a mess, cleanup it a little. – mdaguerre Sep 26 '12 at 21:30
3 Answers
2
****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
2
Bind the .change()
event handler to input
s 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.

João Silva
- 89,303
- 29
- 152
- 158
0
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);
});
});

abmirayo
- 173
- 2
- 15

Scott Selby
- 9,420
- 12
- 57
- 96