Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Swap image with JavaScript

I made a small script for when someone clicks on this eye image the input type was changed from ''password'' to ''text''

function mostrarocultarsenha() {
  var senha = document.getElementById("senha")
  
  if (senha.type == "password") {
    senha.type = "text";
  } else {
    senha.type = "password"
  }
}
<div class="campo">
  <label for="password"><strong>Senha</strong></label>
  <input type="password" name="senha" id="senha" required></input>
</div>

<img class="olho" id="olho" src="https://via.placeholder.com/100" onclick="mostrarocultarsenha()">

Photo from my website

I want that when the input changes from password to text, the image also changes from an eye to an eye with a scratch, and then if clicked again, go back to normal eye, does anyone know how I can do this?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

const olho = document.querySelector("#olho")

if (senha.type === "password") {
   senha.setAttribute("type", "text")
   olho.src = "image link/path"
} else {
   senha.setAttribute("type", "password")
   olho.src = "another image link/path"
}

w3schools

about 4 years ago · Santiago Trujillo Report

0

basically it's just a element ID src it's actually really simple

<div class="campo">
  <label for="password"><strong>Senha</strong></label>
  <input type="password" name="senha" id="senha" required></input>
</div>

<a onclick="mostrarocultarsenha()"><img class="olho" id="olho" src="assets/closedEye.png"/></a>

function mostrarocultarsenha() {
  var senha = document.getElementById("senha")
  
  if (senha.type == "password") {
    senha.type = "text";
    document.getElementById("olho").src = "assets/openedEye.png";
  } else {
    senha.type = "password"
    document.getElementById("olho").src = "assets/closedEye.png";

  }
}

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!