How to make sure that there are spaces and a symbol at the end and that when the value of the slider changes, there are also spaces with the symbol, and now it turns out only when you enter the value from the keyboard, everything is added. Help :(

var inp_1 = $('#test'); var slider2 = $('#runner_2').slider({ range: 'max', min: 100000, max: 1000000, value: 180000, step: 20000, slide: function(event, ui) { // присваеваем значение бегунка инпуту inp_1.val(ui.value); var test = inp_1.val; if (ui.value > 100000) { // если были изменения, то показываем шаг 2 $('.s-calc-step2').css('display', 'block'); } else {} } }); test.onkeypress = event => { // Control buttons if (event.key.length > 1) return true; test.value = (test.value + event.key) .replace(/\D/g, '') .replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ') + '₽'; event.preventDefault(); } 
 <input id="test" type="text"> <div id="runner_2"></div> <link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script> 

1 answer 1

Well, if you understand the question literally, do you get a numerical value from the slider and you need to put this value + text in the slide in the slide? If so then this line

 inp_1.val(ui.value); 

Replace with one where the text will be added to the value:

 inp_1.val( ui.value + " рублей" ); 

But then the reverse extraction from the value of the input number will be a little more difficult, because it is now the text, not the number.