Change of register does not work during input. What could be the error?

function my_keypress2($event) { document.getElementById('div3').innerHTML = document.getElementById('text2').value; var x = ($event.keyCode || $event.which); var x_char2 = String.fromCharCode(x); if ( (x_char2 == 'a') ) { x_char2 = x_char2.replace('a', 'A'); } } 

  • why do you think that doesn't work? - Grundy
  • @Grundy because it does not work)) Symbol replacement does not occur .. - Ksenia
  • How did you check it? - Grundy
  • @Grundy in the code prescribed: <input type = text id = "text2" onKeyPress = my_keypress2 (event);> <div id = "div3"> </ div> </ input> then prescribed that above. After I need to enter the character 'a' in the input field and it should change and appear as 'A' in the div but does not work for me - Ksenia

1 answer 1

Why check something, rewrite something, if you can immediately get what you need?

 function my_keypress2($event) { document.getElementById('div3').innerHTML = document.getElementById('text2').value.toUpperCase(); } 
 <input type=text id="text2" onKeyup="my_keypress2(event);"/> <div id="div3"></div> 

  • for example, in order not to give all the characters in another register, but only selective ones. - Grundy