Change image src when input value is equal to a given value

Asked

Viewed 229 times

4

Good night! I have a login input and an img with the user image. I am trying to change the user image when this input loses focus and if the entered value corresponds to a given value. ex: if I type in this Potato input I will change the src pointing to my potato.png image instead of no-user.png.

<img id="img" src="images/no-user.png" alt="Sem usuário">
<input name="Login" type="text" placeholder="Login" maxlength="20" onblur="carregarFoto(this.value)">

Could someone give me an example?

1 answer

2


I found my answer. I created this function:

function carregarFoto(val) {
    document.getElementById("user").src="images/user.png";
}

and in the input was like this:

<input name="Login" type="text" placeholder="Login" maxlength="20" onblur="carregarFoto(this.value)">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.