-2

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/

1
  • Your code is a mess, cleanup it a little. Commented Sep 26, 2012 at 21:30

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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);        
    });       

});

Example in jsFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.