$( "#length,#width" ).change(function() {
    showArea()
    var kn = $( "#kN" ).val()
    var kgf = $( "#kgf" ).val()
    if(kn!=""){
        showStrengthKN()
    }else{
        showStrengthKGF()
    }
  });
  $("#destructionLocat").change(function(){
      $( "select option:selected" ).each(function() {
          var result=$( this ).text()
          var mode=""
          switch(result){
              case 'A':
                  mode="黏著強度"
                  break;
              case 'B':
                  mode="黏著強度"
                  break;
              default:
                  mode="抗拉強度"
                  break;
          }
          $("#destructionMode").val(mode)
      });
  })
  $( "#kN" ).change(function() {
    showStrengthKN()
    showMpa()
  });
  $( "#kgf" ).change(function() {
    showStrengthKGF()
  });
  function showMpa(){
  
  }
  function showArea(){
      var area=$( "#length" ).val()*$( "#width" ).val()
      $( "#area" ).val(area)
  }
  function showStrengthKN(){ 
     var kn = $( "#kN" ).val()
     var kgf = $( "#kgf" ).val()
      kgf = Math.round(kn*101.97)
      $( "#kgf" ).val(kgf)
      var width=$("#width").val();
      var length=$("#length").val();
      var strengthKGF = getStrength(kgf,width,length)
      console.log("strength"+strengthKGF)
      $("#strengthKGF").val(strengthKGF)
      $("#strengthMPa").val(roundToTwo(strengthKGF*0.0980665))
  }
  function showStrengthKGF(){
     var kgf = $( "#kgf" ).val()
      kn = Math.round(kgf/101.97)
      $( "#kN" ).val(kn)
      var width=$("#width").val();
      var length=$("#length").val();
      var strengthKGF = getStrength(kgf,width,length)
      console.log("strength"+strengthKGF)
      $("#strengthKGF").val(strengthKGF)
      $("#strengthMPa").val(roundToTwo(strengthKGF*0.0980665))
  }
  function getStrength(kgf,width,length){
      return roundToTwo(kgf/(width*length))
  }
  function roundToTwo(num) {
      return +(Math.round(num + "e+2")  + "e-2");
  }