开发者

jQuery Calculation Problem

开发者 https://www.devze.com 2023-01-25 22:20 出处:网络
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'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


use parseInt()

total =  parseInt($('#Qty).val()) * 
    7.85 * 
    parseInt($('#Length').val()) * 
    parseInt($('#Width').val()) * 
    parseInt($('#Gauge').val()) / 1000


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号