[Solved] How to add a single letter filter to input box [closed]


Here is a snippet with two input boxes: the top one defining the replacement rules and the bottom one accepting any text input to be processed:

function mkdict(){
 dict={};
 key.value.split(",").forEach(kv=>{
  let [k,v]=kv.split("=");
  dict[k]=v;
 }); transform();
}
  
function transform(){
 out.textContent=text.value.split("").map(c=>dict[c]||c).join("");
}

var dict;
mkdict();
key.addEventListener("input",mkdict);
text.addEventListener("input",transform);
<input type="text" value="i=!,t=7" id="key"><br>
<input type="text" id="text">
<div id="out"></div>

For the sake of brevity I made use of the fact that DOM elements with id attributes are directly visible in the global name space with their id. This is not considered good (=sustainable and maintainable) style. Instead you should use something like:

const key=document.getElementById("key")

2

solved How to add a single letter filter to input box [closed]