Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. $(document).ready(function() {
  2. $('#OutSum').on('keyup keypress blur change',function () {
  3. checkInt(this);
  4.  
  5. //Проверка на числа
  6. var match = $(this).val().match(/^\d+$/);
  7. if(match){
  8. $('#OutSumButton').prop('disabled', false);
  9. } else {
  10. $('#OutSumButton').prop('disabled', true);
  11. }
  12.  
  13. });
  14.  
  15. $('.triggerinputsum').on('keyup keypress blur change',function () {
  16. checkInt(this);
  17. var text = 'пст.'; // Валюта
  18. var item = $(this); // наш объект
  19. var count = parseInt(item.attr('packetcount')); // ограничение
  20. var price = item.attr('packetprice'); // Цена
  21. var id = item.attr('packetsum'); // id
  22. var value = item.val(); // введено
  23.  
  24. if(value === ''){
  25. value = 1;
  26. }
  27. value = parseInt(value);
  28.  
  29. // Замена при высоком ограничении
  30. if(value > count && count !== 0){
  31. $(this).val(count);
  32. value = count;
  33. }
  34.  
  35. // формат
  36. var result_int = new Intl.NumberFormat('ru-RU').format(value * price);
  37. // вывод
  38. var result = result_int + ' ' + text;
  39. $('#' + id).html(result);
  40.  
  41. });
  42. // функция проверки на символы
  43. function checkInt(item) {
  44. var val = $(item).val();
  45. var preg = val.replace(/[^.\d]+/g,"");
  46. if(preg === '0'){
  47. preg = 1;
  48. }
  49. $(item).val(preg);
  50. }
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement