Reputation: 70
I've been struggling trying to get jQuery to make a calculation for me, and i'm kinda pulling my hair out a bit now!
I need to make a calculation to work out the theoretical weight of a given amount of steel sheets based upon the quantity and the dimensions. The output will be a weight in kg.
The equation is as follows: Qty x 7.85 x Length(mm) x Width(mm) x Gauge(mm) / 1000
The details need to be pulled from form fields and then the result outputted to text or in an input, preferably as the person edits the quantity field.
You can see an example of what i am trying to achieve here: http://www.clifton.rogr.net/enquiry
Upvotes: 0
Views: 373
Reputation: 788
use parseInt()
total = parseInt($('#Qty).val()) *
7.85 *
parseInt($('#Length').val()) *
parseInt($('#Width').val()) *
parseInt($('#Gauge').val()) / 1000
Upvotes: 1
Reputation: 1
for the live update part of your answer you need to use an event handler attached to all of the fields that can have input entered in them. anytime the value in a field changes you need to perform the calculation and set the value of your output field, or element to the result of the calculation
Upvotes: 0