So I have this transliteration function which I need to execute if the checkbox is checked. The issue is that, the function continues to run after the checkbox is unchecked as well.
const checkBox = document.querySelector("#checkbox");
const input = document.querySelector("#input");
function transRussian(){
ch = ch.replace(/l/g, "л");
ch = ch.replace(/p/g, "п");
return ch;
}
checkBox.addEventListener('change',()=>{
if(checkBox.checked){
transliterate();
}
else{
console.log("transliteration is turned off")
}
});
input.addEventListener('keyup',()=>{
var ch = input.value;
transRussian(ch);
input.value = ch;
});
<input type="checkbox" id="checkbox">
<input type="text" id="input">
In this solution, if the translation
checkboxis clicked, thetranslateBlock()method is called and the text inside the<textarea>element is changed according to the logic.