So im making a form where theres an image on an eye that should show the password when clicked and when clicked again it should hide it. i made that when its clicked it change the src attribute of the img and change the type of input
if(img.src = 'images/eye1.png'){
img.src = 'images/eye2.png';
password.type = 'text'
}
and if the img.src is eye2 so after i click the first time it return back to the original
else if(img.src = 'images/eye2.png') {
img.src = 'images/eye1.png';
password.type = 'password'
}
i tried with else too but it doesnt do anything after the first click and i cant find a solution. help please :(
The problem is that you are not verifying any equal condition since you have to use "==" (equal) and not "=" (assignment)
// This line
if(img.src == 'images/eye1.png'){
img.src = 'images/eye2.png';
password.type = 'text';
// and this one
} else if(img.src == 'images/eye2.png') {
img.src = 'images/eye1.png';
password.type = 'password';
}
It is possible to assign a value to a variable in an if. That's why you didn't see an error. I advise you to place the variable to the right side of the ==. Because when you try to assign a value to a text, the console will display an error, because the text is not a left value
Example:
if('images/eye2.png' == img.src) {
// your code
}