I am editing a code from here to make an alphabet convert into another set alphabet, in other words, my intention is to make an online textarea keyboard for a foreign alphabet.
This is my code which I have edited from above:
<textarea id="txt"></textarea>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$('#txt').on('keypress', function (e) {
var pressedKey = String.fromCharCode(e.keyCode);
var $txt = $('#txt');
e.preventDefault();
if(pressedKey == 'q') {$txt.val($txt.val() + 'ф');}
if(pressedKey == 'w') {$txt.val($txt.val() + 'ц');}
if(pressedKey == 'e') {$txt.val($txt.val() + 'у');}
if(pressedKey == '') {$txt.val($txt.val() + '');} .......
});
</script>
For every latin alphabet there is one cyrillic alphabet. Considering there are uppercase letters and punctuation marks as well, there are certainly a lot of 'if(pressedKey == '') {$txt.val($txt.val() + '');}
's to make.
How can I simplify this code, instead of making more than 50 rows of almost the same line?
I have referred to many sources and have tried many approaches with my short knowledge, I also tried to include var
into my Javascript as many sources recommended doing so, but cannot think of a good way. Any help will be greatly appreciated.