If else in calculated form, calculate cubic meter = height * square meter or cubic meter = length * width * height

In my Form I let the user to enter length height and width of a room to get the calculated values for m2, m3 and Watt. But the user should also be able to put just directly height and m2 to get the Values. I have tried many syntaxes but if else doesn't work correctly. I know I have to somehow empty the the variables, I tried it by the form reset function.

$(document).ready(function() {
  // https://allaboutbasic.com/2017/08/25/how-to-add-auto-calculation-fields-or-calculator-in-contact-form-7-using-jquery/;

  var le; // länge
  var wi; // breite
  var he; // höhe
  var m2; // quadrat Meter
  var m3; // Kubik Meter
  var wt1 = 40; // Watt per Kubik

  if (!document.getElementById("le").value || !document.getElementById("wi").value) {

    $("#le").on("change", function() {
      le = parseInt(this.value, 10);
      $("#wi").on("change", function() {
        wi = parseInt(this.value, 10);
        $("#he").on("change", function() {
          he = parseInt(this.value, 10);
          m2 = le * wi;
          m3 = le * wi * he;
          wt = m3 * wt1 / 1000;
          // runden ohne dezimalstellen "(toFixed(2)) zwei Stellen"
          $("#m2").val(m2.toFixed());
          $("#m3").val(m3.toFixed());
          $("#wt").val(wt.toFixed(3));
        });
      });
    });
  } else {
    $("#he").on("change", function() {
      he = parseInt(this.value, 10);
      $("#m2").on("change", function() {
        m2 = parseInt(this.value, 10);
        m3 = m2 * he;
        wt = m3 * wt1 / 1000;
        $("#m2").val(m2.toFixed());
        $("#m3").val(m3.toFixed());
        $("#wt").val(wt.toFixed(3));
      });
    });
  }
});

function resetcalcform() {
  document.getElementById("calcForm").reset();
  le = undefined; // unset länge
  wi = undefined; // unset breite
  he = undefined; // unset höhe
  m2 = undefined; // unset quadrat Meter
  m3 = undefined; // unset Kubik Meter
};
label {
  display: block;
}

input {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div class="kaecalc ">
  <form id="calcForm" name="data_entry" action="#" autocomplete="off">
    <div>
      <label class="" for="le">Länge in m</label>
      <input type="text" class="2" id="le">
      <!-- "text" type um "," als dezimal eingabe zu erlauben -->
    </div>
    <div>
      <label class="" for="wi">Breite in m</label>
      <input type="text" id="wi">
    </div>
    <div>
      <label class="" for="he">Höhe in m </label>
      <input type="text" id="he">
    </div>
    <div>
      <label class="" for="m2">m2 </label>
      <input type="number" id="m2">
    </div>
    <div>
      <label class="" for="m3">m3 </label>
      <input type="number" id="m3">
    </div>
    <div>
      <label class="" for="watt">KW der Anlage</label>
      <input type="number" id="wt">
    </div>
  </form>
  <!-- button MTS Styles -->
  <p align="right"><span class="">
    <button id="tdmyb1" class="" role="button" onclick="resetcalcform()"><span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text">reset</span></button>

  var le; // länge
  var wi; // breite
  var he; // höhe
  var m2; // quadrat Meter
  var m3; // Kubik Meter
  var wt1 = 40; // Watt per Kubik
var wt;
var props ={};
$(document).ready(function() {
  // https://allaboutbasic.com/2017/08/25/how-to-add-auto-calculation-fields-or-calculator-in-contact-form-7-using-jquery/;



 

    $("#le,#wi,#he,#m2").on("change", function() {
  m2=m3=wt=undefined;

      props[this.id] = parseInt(this.value, 10);
        
        if(props.le && props.wi && props.he){    
 m2 = props.le * props.wi;        
          m3 = props.le * props.wi * props.he;
          wt = m3 * wt1 / 1000;

}else if(props.m2 && props.he){
m2 = props.m2;
   m3 = props.m2 * props.he;
          wt = m3 * wt1 / 1000;
}else if(props.le && props.wi){
          m2 = props.le * props.wi;
 
}
          // runden ohne dezimalstellen "(toFixed(2)) zwei Stellen"
         $("#m2").val(m2 && m2.toFixed());
          $("#m3").val(m3 && m3.toFixed());
          $("#wt").val(wt && wt.toFixed(3));
      
    });
 
});

function resetcalcform() {
  document.getElementById("calcForm").reset();
  le = undefined; // unset länge
  wi = undefined; // unset breite
  he = undefined; // unset höhe
  m2 = undefined; // unset quadrat Meter
  m3 = undefined; // unset Kubik Meter
wt = undefined;
props ={};

};
label {
  display: block;
}

input {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div class="kaecalc ">
  <form id="calcForm" name="data_entry" action="#" autocomplete="off">
    <div>
      <label class="" for="le">Länge in m</label>
      <input type="text" class="2" id="le">
      <!-- "text" type um "," als dezimal eingabe zu erlauben -->
    </div>
    <div>
      <label class="" for="wi">Breite in m</label>
      <input type="text" id="wi">
    </div>
    <div>
      <label class="" for="he">Höhe in m </label>
      <input type="text" id="he">
    </div>
    <div>
      <label class="" for="m2">m2 </label>
      <input type="number" id="m2">
    </div>
    <div>
      <label class="" for="m3">m3 </label>
      <input type="number" id="m3">
    </div>
    <div>
      <label class="" for="watt">KW der Anlage</label>
      <input type="number" id="wt">
    </div>
  </form>
  <!-- button MTS Styles -->
  <p align="right"><span class="">
    <button id="tdmyb1" class="" role="button" onclick="resetcalcform()"><span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text">reset</span></button>

How to Calculate Cubic Meters, You can use a cubic meter calculator to work between SI (international Even if you know that cubic meters (m3) represent a unit of volume in physical For example, a rectangular box with a length of 2 m, a width of 1 m, and a height of 0.5 m would For example, if one side of the square is 5 feet, the equation is 5 time 5� If your unit of measurement is not meter, convert the unit to meter first, then, multiply length, width and height values together, this will give you the volume of the cube. For example : How to calculate the volume(CBM) of a carton that dimension is 42 x 37 x 28 cm ?

Please see if the following code suits your scenario:

$(document).ready(function() {
    var le // länge
      , wi // breite
      , he // höhe
      , m2 // quadrat Meter
      , m3 // Kubik Meter
      , wt1 // Watt per Kubik
    
  function resetcalcform(){  
    le = ""
    , wi = ""
    , he = ""
    , m2 = ""
    , m3 = ""
    , wt1 = 40
    $("#le, #wi, #he, #m2, #m3, #wt").val("")
  }
  
  function getArea(l, b){
    if(l != "" && b != ""){
      return (parseInt(l) * parseInt(b)).toFixed(2)
    } else return ""
  }
  
  function getVolume(l, b, h){
    if(l != "" && b != "" && h != ""){
      return (parseInt(l) * parseInt(b) * parseInt(h)).toFixed(2)
    } else return ""
  }
  
  function getWatt(v){
    if(v != ""){
      return ((parseInt(v) * wt1) / 1000).toFixed(2)
    } else return ""
  }  
  
  // On change of length
  $("#le").on("change", function() {
    // Set length variable
    le = this.value
     
    // Calculate area
    var area = getArea(le, wi)
    $("#m2").val(area)    
     
    // Calculate Volume
    var volume = getVolume(le, wi, he)
    $("#m3").val(volume)
    
    // Calculate Watt
    var watt = getWatt(volume)
    $("#wt").val(watt)
  })
  
  // On change of width
  $("#wi").on("change", function() {
    // Set width variable
    wi = this.value
     
    // Calculate area
    var area = getArea(le, wi)
    $("#m2").val(area)    
     
    // Calculate Volume
    var volume = getVolume(le, wi, he)
    $("#m3").val(volume)
    
    // Calculate Watt
    var watt = getWatt(volume)
    $("#wt").val(watt)
  })
  
  // On change of height
  $("#he").on("change", function() {
    // Set height variable
    he = this.value
    
    // Calculate Volume
    var volume = getVolume(le, wi, he)
    $("#m3").val(volume)
    
    // Calculate Watt
    var watt = getWatt(volume)
    $("#wt").val(watt)
  })
  
  resetcalcform()
  
  $("button#tdmyb1").on("click", function(){
    resetcalcform()
  })
  
})
label {
  display: block;
}

input {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div class="kaecalc ">
  <form id="calcForm" name="data_entry" action="#" autocomplete="off">
    <div>
      <label class="" for="le">Länge in m</label>
      <input type="text" class="2" id="le">
      <!-- "text" type um "," als dezimal eingabe zu erlauben -->
    </div>
    <div>
      <label class="" for="wi">Breite in m</label>
      <input type="text" id="wi">
    </div>
    <div>
      <label class="" for="he">Höhe in m </label>
      <input type="text" id="he">
    </div>
    <div>
      <label class="" for="m2">m2 </label>
      <input type="number" id="m2">
    </div>
    <div>
      <label class="" for="m3">m3 </label>
      <input type="number" id="m3">
    </div>
    <div>
      <label class="" for="watt">KW der Anlage</label>
      <input type="number" id="wt">
    </div>
  </form>
  <!-- button MTS Styles -->
  <p align="right"><span class="">
    <button id="tdmyb1" class="" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text">reset</span></button>

CBM Calculator (mm,cm,m,in,ft,yd to cubic meter, cuboid volume), You'll need to know the length, width, and height of the rectangular carton. Use a measuring tape to find all three distances and mark them down separately. If you � The cubic meter calculator is used to calculate the volume of a shipment carton or box by using the three dimensions, which are length, width, and height. CBM Calculator is heavily used in the shipping industry including rail, air, and water transport. They rely on cubic meters to calculate the size or weight of the shipment.

This should solve your case:

$(document).ready(function() {
  // https://allaboutbasic.com/2017/08/25/how-to-add-auto-calculation-fields-or-calculator-in-contact-form-7-using-jquery/;

  var le; // länge
  var wi; // breite
  var he; // höhe
  var m2; // quadrat Meter
  var m3; // Kubik Meter
  var wt1 = 40; // Watt per Kubik
  
  function tryGetNumber(id){
    var element = document.getElementById(id);
    if(element.value){
      return parseInt(element.value, 10);
    } else {
      return null;
    }
  }
  
  function resetElement(id){
    var element = document.getElementById(id);
    element.value = null;
  }
  
  function recalculate(force_m2, force_m3){
    le = tryGetNumber("le");
    wi = tryGetNumber("wi");
    if(le && wi){
      m2 = le * wi;
      $("#m2").val(m2.toFixed());
    } else {
      m2 = force_m2;
    }
    he = tryGetNumber("he");
    if(m2 && he){
      m3 = m2 * he;
      $("#m3").val(m3.toFixed());
    } else {
      m3 = force_m3;
    }
    var wt = null;
    if(m3){
      wt = m3 * wt1 / 1000;
      $("#wt").val(wt.toFixed(3));
    }
  }
  
  function m2Updated(){
    resetElement("le");
    resetElement("wi");
    m2 = tryGetNumber("m2");
    recalculate(m2);
  }
  
  function heUpdated(){
    m2 = tryGetNumber("m2");
    recalculate(m2);
  }
  
  function m3Updated(){
    resetElement("le");
    resetElement("wi");
    resetElement("he");
    resetElement("m2");
    m3 = tryGetNumber("m3");
    recalculate(null, m3);
  }
  
   $("#le").on("change", recalculate);
   $("#wi").on("change", recalculate);
   $("#he").on("change", heUpdated);
  
   $("#m2").on("change", m2Updated);
   $("#m3").on("change", m3Updated);
});

function resetcalcform() {
  document.getElementById("calcForm").reset();
  le = undefined; // unset länge
  wi = undefined; // unset breite
  he = undefined; // unset höhe
  m2 = undefined; // unset quadrat Meter
  m3 = undefined; // unset Kubik Meter
};
label {
  display: block;
}

input {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div class="kaecalc ">
  <form id="calcForm" name="data_entry" action="#" autocomplete="off">
    <div>
      <label class="" for="le">Länge in m</label>
      <input type="number" class="2" id="le">
      <!-- "text" type um "," als dezimal eingabe zu erlauben -->
    </div>
    <div>
      <label class="" for="wi">Breite in m</label>
      <input type="number" id="wi">
    </div>
    <div>
      <label class="" for="he">Höhe in m </label>
      <input type="number" id="he">
    </div>
    <div>
      <label class="" for="m2">m2 </label>
      <input type="number" id="m2">
    </div>
    <div>
      <label class="" for="m3">m3 </label>
      <input type="number" id="m3">
    </div>
    <div>
      <label class="" for="watt">KW der Anlage</label>
      <input type="number" id="wt">
    </div>
  </form>
  <!-- button MTS Styles -->
  <p align="right"><span class="">
    <button id="tdmyb1" class="" role="button" onclick="resetcalcform()"><span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text">reset</span></button>

CBM Calculator, Calculate the cubic meter for your shipment with Freightos' free CBM Calculator. CBM measurement is calculated by multiplying the width, height and length If your shipment has different sized items, simply repeat the formula for each size and whether they square the circle (the diameter becomes width and height) or � Besides, for doing the calculation of cubic meter you need the measurement of the object, the formula, and knowledge of basic maths. The formula is = length × breadth × height or l × b × h Generally, the word ‘a’ (small a) is used to symbolize the formula of a cube and it is written as a 3 .

Cubic Meters Calculator, Calculate the cubic meters of a space given the length, width, and height measurements in millimeters, centimeters, meters, and even inches and feet. This is� BMI Calculator » Triangle Calculators » Length and Distance Conversions » SD SE Mean Median Variance » Blood Type Child Parental Calculator » Unicode, UTF8, Hexidecimal » RGB, Hex, HTML Color Conversion » G-Force RPM Calculator » Chemical Molecular Weight Calculator » Mole, Moles to Grams Calculator » R Plot PCH Symbols » Dilution

Room Volume Calculator, Calculate volume capacity from length, width and height; User Guide. Volume flow is usually measured in Cubic Feet per Minute (CFM). is calculated by the Width * Length * Height, measured in m 3. b) (2 marks) If the. 5 for Rectangle, Square, or Free-Form pools. uk's Volume of a Cylinder Calculator – Use this tool to� Thus, if 1 cubic meter equals 35.3 cubic feet, how many cubic meters will, for example, 67 cubic feet be? Multiply 35.5 by 1 and divide it by your cubic feet measurement: 35.3 x 1= 35.3 , 67÷35.3 = 1.89 square feet. Calculate cubic meters from cubic yards. Again, to convert cubic yards to cubic meters, we'll also have to apply the rule of three.

[PDF] What is the same and what is different about measuring two , C 8 square units D 9 square units Metric units of length are millimetres (mm), centimetres (cm), metres (m) and If you start by estimating a length, you can decide whether your length Find an object that has a length dimension (length, width or height) of 1 mm. Calculating area of a rectangle using a formula. A cubic meter is a space in the shape of a cube 1 m on a side or the equivalent. For example, a rectangular box with a length of 2 m, a width of 1 m, and a height of 0.5 m would have a volume of 1 m 3 (1 × 2 × 0.5 = 1).

Comments
  • This works for the Page where I use jQuery Version 1.11.3. In Wordpress but, the reset of the variables doesn't do. jQuery.noConflict(); (function( $ ) { $(function() { // More code using $ as alias to jQuery }); })(jQuery);
  • if go to put height (he) and m2 directly it's not working