pesticide.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. function getQuantity()
  2. {
  3. var size = document.getElementById("terrain_size").value;
  4. var water = document.getElementById("water").value;
  5. var concentration = document.getElementById("concentration").value;
  6. var sprayer = document.getElementById("sprayer").value;
  7. size = size.replace(",", ".");
  8. water = water.replace(",", ".");
  9. concentration = concentration.replace(",", ".");
  10. sprayer = sprayer.replace(",", ".");
  11. size = size.replace(/[^0-9$.,]/g, '');
  12. water = water.replace(/[^0-9$.,]/g, '');
  13. concentration = concentration.replace(/[^0-9$.,]/g, '');
  14. sprayer = sprayer.replace(/[^0-9$.,]/g, '');
  15. terrain_unit = $( "#terrain_unit option:selected" ).text();
  16. concentration_unit = $( "#concentration_unit option:selected" ).text();
  17. $("#result").text("");
  18. $("#result-text").text("");
  19. $("#result-sprayer").text("");
  20. $("#result-sprayer-text").text("");
  21. var concentrationProc;
  22. var unit = "kg";
  23. if (!size)
  24. size = 1;
  25. if (terrain_unit == "a")
  26. size /= 100;
  27. else if (terrain_unit == "m2")
  28. size /= 10000;
  29. if (concentration_unit == "%")
  30. concentrationProc = concentration*1000/water;
  31. else if (concentration_unit == "kg/ha")
  32. {
  33. concentrationProc = concentration*100/water;
  34. unit = "kg";
  35. }
  36. else if (concentration_unit == "l/ha")
  37. {
  38. concentrationProc = concentration*100/water;
  39. unit = "l";
  40. }
  41. else if (concentration_unit == "dl/ha")
  42. {
  43. concentrationProc = concentration*100/water/10;
  44. unit = "l";
  45. }
  46. else if (concentration_unit == "dag/ha")
  47. {
  48. concentrationProc = concentration*100/water/100;
  49. unit = "kg";
  50. }
  51. else if (concentration_unit == "cl/ha")
  52. {
  53. concentrationProc = concentration*100/water/100;
  54. unit = "l";
  55. }
  56. else if (concentration_unit == "g/ha")
  57. {
  58. concentrationProc = concentration*100/water/1000;
  59. unit = "kg";
  60. }
  61. else if (concentration_unit == "ml/ha")
  62. {
  63. concentrationProc = concentration*100/water/1000
  64. unit = "l";
  65. }
  66. if (size && concentration && water)
  67. {
  68. if (concentration_unit == '%')
  69. quant = 10*concentration*size
  70. else
  71. quant = water*concentrationProc*size/100;
  72. if (quant < 0.01)
  73. {
  74. quant *= 1000;
  75. if (unit == "kg")
  76. unit = "g";
  77. else
  78. unit = "ml";
  79. }
  80. if (sprayer)
  81. {
  82. divider = water*size/sprayer
  83. response = quant/divider;
  84. sprayerUnit = unit;
  85. if (response < 0.01)
  86. {
  87. if (unit == "kg")
  88. {
  89. sprayerUnit = "g"
  90. response *= 1000;
  91. }
  92. else if (unit == "l")
  93. {
  94. sprayerUnit = "ml"
  95. response *= 1000;
  96. }
  97. }
  98. $("#result-sprayer-text").text("For a single sprayer, use ");
  99. $("#result-sprayer").text(response.toFixed(2)+sprayerUnit+" of plant protector.");
  100. }
  101. $("#result-text").text("Based on the entered data, we advise you to use ");
  102. $("#result").text(quant.toFixed(2)+unit+" of plant protector.");
  103. }
  104. else
  105. $("#result-text").text("To calculate the amount of plant protector, you should minimally enter the amount of water, hectares, and requested concentration.");
  106. }
  107. $("input[type=number]").keydown(function (e) {
  108. var key = e.which ? e.which : event.keyCode;
  109. if (key == 110 || key == 188) {
  110. e.preventDefault();
  111. var value = $(this).val();
  112. //console.log(value);
  113. $(this).val(value);
  114. }
  115. });