I want to call a function Encode
when a button is clicked.
My code is:
let data = document.getElementById("d1");
let encode = document.getElementById("btnEncode");
let encrypt = document.getElementById("btnEncrypt");
let display = document.getElementById("i1");
let form = document.getElementById("form1");
function Encode() {
let l = data.value;
console.log(l);
l = btoa(l);
display.value = l;
console.log(l);
}
When I use encode.onclick=Encode();
the value of l
is empty in Encode()
and when I use encode.addEventListener("click", Encode);
, it works fine.
Can anyone tell me the reason?