volCal.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. function calculation_bw () {
  2. let width = document.getElementById('box_unit_width').value;
  3. let length = document.getElementById('box_unit_length').value;
  4. let height = document.getElementById('box_unit_height').value;
  5. let wType = document.querySelector(`input[name="box_radio"]:checked`).value;
  6. let result = 0;
  7. let targetInput = document.getElementById('weight');
  8. if (checkVariables(width, length, height)) {
  9. if (wType === 'kg') {
  10. result = ((width * height * length) / 6000).toFixed(3) + ' KG';
  11. } else {
  12. result = ((width * height * length) / 166).toFixed(3) + ' ib';
  13. }
  14. } else {
  15. alert('입력값을 확인하세요');
  16. return false;
  17. }
  18. targetInput.value = result;
  19. }
  20. function calculation_cw () {
  21. let width = document.getElementById('cy_unit_width').value;
  22. let length = document.getElementById('cy_unit_length').value;
  23. let wType = document.querySelector(`input[name="cy_radio"]:checked`).value;
  24. let result = 0;
  25. let targetInput = document.getElementById('weight2');
  26. if (checkVariables(width, length)) {
  27. if (wType === 'kg') {
  28. result = (((Math.round(width * width * Math.PI * 1000) / 1000) * length) / 6000).toFixed(3) + ' KG';
  29. } else {
  30. result = (((Math.round(width * width * Math.PI * 1000) / 1000) * length) / 166).toFixed(3) + ' ib';
  31. }
  32. } else {
  33. alert('입력값을 확인하세요');
  34. return false;
  35. }
  36. targetInput.value = result;
  37. }
  38. function calculation_bc () {
  39. let width = document.getElementById('box_unit_width1').value;
  40. let length = document.getElementById('box_unit_length1').value;
  41. let height = document.getElementById('box_unit_height1').value;
  42. let count = document.getElementById('box_unit_count').value;
  43. let wType = document.querySelector(`input[name="box_radio1"]:checked`).value;
  44. let result = 0;
  45. let targetInput = document.getElementById('weight3');
  46. if (checkVariables(width, length, height)) {
  47. if (wType === 'kg') {
  48. result = ((width * height * length) / 1000000).toFixed(3) + ' CBM';
  49. } else {
  50. result = (((width * height * length) / 1728) / 35.3147).toFixed(3) + ' CBM';
  51. }
  52. } else {
  53. alert('입력값을 확인하세요');
  54. return false;
  55. }
  56. targetInput.value = result;
  57. }
  58. function calculation_cc () {
  59. let width = document.getElementById('box_unit_width1').value;
  60. let length = document.getElementById('box_unit_length1').value;
  61. let height = document.getElementById('box_unit_height1').value;
  62. let count = document.getElementById('box_unit_count').value;
  63. let wType = document.querySelector(`input[name="box_radio1"]:checked`).value;
  64. let result = 0;
  65. let targetInput = document.getElementById('weight4');
  66. if (checkVariables(width, length, height)) {
  67. if (wType === 'kg') {
  68. result = (((Math.round(width * width * Math.PI * 1000) / 1000) * length) / 1000000).toFixed(3) + ' CBM';
  69. } else {
  70. result = (((width * height * length) / 1728) / 35.3147).toFixed(3) + ' CBM';
  71. }
  72. } else {
  73. alert('입력값을 확인하세요');
  74. return false;
  75. }
  76. targetInput.value = result;
  77. }
  78. function checkVariables() {
  79. for (let i = 0; i < arguments.length; i++) {
  80. // 변수가 null 또는 undefined이면 false 반환
  81. if (arguments[i] === null || arguments[i] === undefined) {
  82. return false;
  83. }
  84. // 변수가 숫자가 아니면 false 반환
  85. if (isNaN(arguments[i])) {
  86. return false;
  87. }
  88. }
  89. // 모든 변수가 조건을 만족하면 true 반환
  90. return true;
  91. }