A
A
Alex Mirgorodskiy2018-03-02 18:00:04
JavaScript
Alex Mirgorodskiy, 2018-03-02 18:00:04

How to make printing in uppercase only the letter "a"?

Hi friends, there is a problem, I’m just learning in js, so I don’t know banal things ...
there is an input, I enter text into it, and I need the entered text to be displayed immediately in the div below (I sort of figured it out) But you need to if the letter a got into the input, then it was transferred to the div in upper case, can you help?)

function my_keyup() {
      txt = document.getElementById('value_for_div3').value;
      document.getElementById("div3").innerHTML = txt;

  }

//Напечатан символ
  function my_keypress($event)
  {

//Код клавиши
      var x = ($event.keyCode || $event.which);
      var x_char = String.fromCharCode(x);

      //Если буква а(русская)
      if (x_char=='а') {
          

      }


  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-03-02
@AlexWeb6667

There is an easier way:

var div = document.getElementById("div3");
var input = document.getElementById('value_for_div3');

input.addEventListener('keyup', function(e) {
  div.innerHTML = this.value.replace(/а/g, 'A');
});

In this example, only "a" from Cyrillic is replaced.
If you need to replace both Cyrillic and Latin, then replace the regular expression with:
The symbols look the same, but their codes are different.
Demo.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question