There is a certain amount of input.price-all when entered into which fractional digits should be written on the fly in value="" integers with increasing Math.ceil despite the punctuation mark ( Math.ceil stop or comma), but they should remain in the field itself As they were entered. Example:

In the field: 12,34 or 12.34 in the value value="13"

 <input type="text" class="price-all" value="" /> <input type="text" class="price-all" value="" /> <input type="text" class="price-all" value="" /> <input type="text" class="price-all" value="" /> <input type="text" class="price-all" value="" /> 
  • On the fly at what time? When the focus disappears from the field? When you press Enter? Every moment? Then how do you basically enter the point? In any case, you can try to do it through delegates (events generally speaking). - Bloodskys
  • "while in the field itself ..." - the value attribute value - this is what you see in the "field itself". Explain what you really need. - Igor

2 answers 2

I propose such a solution. There is an oninput event that is triggered by any change in the field.

 $(function() { $('input').on('input', function() { var val = $(this).val().replace(/\,/g, '.'); $(this).attr('value', Math.ceil(val)); }); $('button').click(function() { alert($('input').attr('value')); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text"> <button>Показать value</button> 

  • Yuri, "the value of the value attribute is what you see in the" field itself ", I know that. But it is important for me that when sending the form, integers are transmitted. For some reason, only the first available field works with the example you cited, but what about the rest? - Eugene
  • In the sense of the first available field? This property can be applied to any text input. Why don't you, when getting a value from input, round it before sending it, in this case? - Yuri
  • I agree, it is possible and so, just in my head there was a slightly different idea. - Eugene

It is necessary to hang an event on these inputs (for example, onfocusout) and set it to the value Math.ceil.