V
V
Viktor2020-05-07 14:42:26
JavaScript
Viktor, 2020-05-07 14:42:26

How to add text to input?

5eb3f41091b71210828911.png
How can I add m2 to the input?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
forspamonly2, 2020-05-08
@polyak-888

N
n1ksON, 2020-05-07
@n1ksON

Use value to add text to forms.

A
Alexander Marchuk, 2020-05-07
@imhvost

document.querySelector('input').addEventListener('input', function(){
  let value = this.value;
  if(!value) return;
  value = value.replace(/ м²/g, '');
  this.value = value + ' м²';
}, false);

codepen

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question