# Volumetric weight script

Hello,

I'm looking for a simple script that will calculate the Volumetric weight of a box and for a tube.
All weights should be rounded off upwards. When possible in "cm" to "kg"
It has to be a simple 1 since I'm not so good with javascripting

regards,
Martijn
###### 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.

Commented:
Hi

Below are two functions to calcumate the volumetric weight of a box and a tube and examples of how to call them.

The scripts work in cm to kg.

<script language="javascript">

function weightBox(intLen, intWid, intHei)
{
return Math.round((intLen * intWid * intHei) / 6000);
}

function weightTube(intLen, intWid)
{
return Math.round((intLen * ((intWid/2 * intWid/2) * Math.PI)) / 6000);
}

</script>

Cheers

Scott
0
Author Commented:
Great, but how to put them in a mhtl page??
0
Author Commented:
I mean html.... ;-)
0
Commented:
Something like this?

The script is in the head of the following HTML doc, and it's called calc().  I used the following formulae for volumetric weight:

BOX:  l*w*h / 6000
TUBE: l*w / 6000

(and by tube, I assume you mean shipping tube...)

=== code ========================================
<html>
<script>

function calc()
{
var length = document.f.l.value;
var width = document.f.w.value;
var height = document.f.h.value;

if ( document.f.type[0].checked == true ) {
if ( length > 0 && width > 0 && height >0 )
document.f.ans.value = length*width*height/6000;
else
document.f.ans.value = 0;
}

else {
if ( length > 0 && width > 0 )
document.f.ans.value = length*width/6000;
else
document.f.ans.value = 0;
}
}

</script>
<form name="f">
<br>
<input type="text" name="l" size="5">Length (cm)
<br>
<input type="text" name="w" size="5">Width (cm)
<br>
<input type="text" name="h" size="5">Height (cm)
<br>
<button onClick="calc();">Calculate</button>
<br>
Volumetric Weight (kg):
<input type="text" size="20" name="ans" disabled>
</form>

</body>
</html>
=== end code =====================================

baboo_
0
Commented:
Whoops - use this calc function...  Didn't see the rounding requirement...

function calc()
{
var length = document.f.l.value;
var width = document.f.w.value;
var height = document.f.h.value;

if ( document.f.type[0].checked == true ) {
if ( length > 0 && width > 0 && height >0 )
document.f.ans.value = Math.round(length*width*height/6000);
else
document.f.ans.value = 0;
}

else {
if ( length > 0 && width > 0 )
document.f.ans.value = Math.round(length*width/6000);
else
document.f.ans.value = 0;
}
}
0

Experts Exchange Solution brought to you by

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

Commented:
I checked with DHL's website, and they calculate the voumetric weight of a "tube" as (length*width/6000).  Of course, if you mean "cylinder" instead of tube, by which they seem to show a long triangular prism-shape, use (length*(width/2 * width/2) * Math.PI ) / 6000

baboo_
0
Author Commented:
so (length*(width/2 * width/2) * Math.PI ) / 6000 for a cylinder like on the dhl website??
0
Commented:
No - they only had a calculator for a "box" and "tube."  And by "tube" they meant a long triangular prism shape, not a cylinder.  But their formula for international volumetric weight was (volume/6000).  Here's a link:

http://www.dhl.com/publish/g0/en/tools/volume.high.html

baboo_
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.