[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Volumetric weight script

Posted on 2004-11-29
8
Medium Priority
?
346 Views
Last Modified: 2012-05-05
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

please help me out.

regards,
Martijn
0
Comment
Question by:mvanthof
  • 4
  • 3
8 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 12695014
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">

alert(weightBox(100,100,100));

alert(weightTube(100,100));

  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 Comment

by:mvanthof
ID: 12695047
Great, but how to put them in a mhtl page??
0
 

Author Comment

by:mvanthof
ID: 12695056
I mean html.... ;-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:baboo_
ID: 12695057
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>
<head>
<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>
</head>
<body onLoad="">
<form name="f">
      <input type="radio" name="type" checked>Box
      <input type="radio" name="type">Tube
      <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
 
LVL 3

Accepted Solution

by:
baboo_ earned 1000 total points
ID: 12695063
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
 
LVL 3

Expert Comment

by:baboo_
ID: 12695076
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 Comment

by:mvanthof
ID: 12695122
so (length*(width/2 * width/2) * Math.PI ) / 6000 for a cylinder like on the dhl website??
0
 
LVL 3

Expert Comment

by:baboo_
ID: 12703270
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question