use jquery to calculate input

have a look at the sample image

There could ba 2 (or) more rows with input fields.

Now, I want to use JQuery to be able to the following:
If I change one element, it changes the value of other fields.
e.g. for the 1st row if I change the value from 2 to 3, the result should change to 9.
the calculation has to be on a row by row basis.

how do I do it?
test.png
manivineetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David H.H.LeeCommented:
Hi manivineet,
You may try this jQuery plugin called Calculation Plug-in
http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm
0
Andyc75Software ArchitectCommented:
Here is some code I wrote that does what you described in the image

If the value in row 1 changes the total will change in row 1.
if the value in row 2 changes the total will change in row 2


<html>
<head>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
	<script type="text/javascript">
	  $(document).ready(function(){
	  
		$('.row1').change(function(){
			  var inputA = $('#row1_inputA').val();
			  var inputB = $('#row1_inputB').val();
			  $('#row1_total').val(inputA * inputB);	
		 });
		 
		 $('.row2').change(function(){
			  var inputA = $('#row2_inputA').val();
			  var inputB = $('#row2_inputB').val();
			  $('#row2_total').val(inputA * inputB);	
		 });
	  
	  });
	</script>
</head>
<body>
	<form>
	<table><tr>
		<td>
		<input id="row1_inputA" class="row1" type="text" value="2"/>
		<input id="row1_inputB" class="row1" type="text" value="2"/>
		<input id="row1_total" type="text" value="6"/>
		</td>
	</tr><tr>
		<td>
		<input id="row2_inputA" class="row2" type="text" value="3"/>
		<input id="row2_inputB" class="row2" type="text" value="4"/>
		<input id="row2_total" type="text" value="12"/>
		</td>
	</tr>
	</form>
</body>

</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
manivineetAuthor Commented:
Thanks Andy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.