I want to change the text in an input form to "*" as the user is typing. I have figured out how to change the text to asterisks and it shows in the console as asterisks but I can't get to change the text while the user is typing. Here is my code:
const cardNumber = document.getElementById("input");
const reg = new RegExp("^[0-9]*$");
cardNumber.addEventListener("keyup", function changeChar(){
if(cardNumber.value.length <= 12){
for(i=0; i<cardNumber.value.length; i++){
const newValue = cardNumber.value[i].replace(reg, "*");//Replaces the number with an asterisk
console.log(newValue);//Outputs as asterisks on the console
cardNumber.value[i].innerHTML = newValue;//This doesn't seem to do the trick
}
}
});
I tried changing the value of the text with .value and .innerHTML method but it didn't work out. I expect the text to change to asterisks as the user is typing.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/UjF2Rak
Comments
Post a Comment