Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 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 = parseInt(item.val()); // введено
  23.  
  24.  
  25. // Замена при высоком ограничении
  26. if(value > count && count !== 0){
  27. $(this).val(count);
  28. value = count;
  29. }
  30.  
  31. // формат
  32. var result_int = new Intl.NumberFormat('ru-RU').format(value * price);
  33. // вывод
  34. var result = result_int + ' ' + text;
  35. $('#' + id).html(result);
  36.  
  37. });
  38. // функция проверки на символы
  39. function checkInt(item) {
  40. var val = $(item).val();
  41. var preg = val.replace(/[^.\d]+/g,"");
  42. if(preg === '0'){
  43. preg = 1;
  44. }
  45. $(item).val(preg);
  46. }
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement