Change image src when input value equals a given value

4

Good evening! I have a login input and an img with the user image. I'm trying to change the user's image when this input loses focus and the value entered matches a given value. ex: if I type in this input Potato I will change the src pointing to my image potato.png 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?

    
asked by anonymous 07.12.2015 / 23:47

1 answer

2

I found my answer. I created this function:

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

and no input looks like this:

<input name="Login" type="text" placeholder="Login" maxlength="20" onblur="carregarFoto(this.value)">
    
08.12.2015 / 00:01