Beispiel:HTML input-password.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="./Beispiel:SELFHTML-Beispiel-Grundlayout.css">
<title>Passwort sichtbar machen</title>
<style>
form {
  width: 30em;
  padding-top: 3em;
}
input, label {
  float: left;
}
input {
  margin: 0 0 1em .2em;
  padding: .2em .5em;
  width: 65%;
  background-color: #fffbf0; 
  border: 1px solid #e7c157;  
}
label { 
  text-align: right;
  line-height: 1.5;
  width: 30%;
}
label::after {
  content: ": ";
}
button {
  margin: 0 0 1em 30% ;
}

button { 
  padding: .4em .8em; 
  background: #3983ab linear-gradient(hsla(0, 0%, 100%,.2), transparent); 
  border: 1px solid rgba(0,0,0,.1);
  border-radius: 0 0.4em 0.4em 0.4em; 
  box-shadow: 0 .2em 0.4em rgba(0,0,0,.5); 
  color: white;
  text-shadow: 0 -.05em .05em rgba(0,0,0,.5); 
  line-height: 1.5;
}

button.cancel {
  background-color: #c32e04;
}

button.ok {
  background-color: #5a9900;
}
</style>
<script>
'use strict';
document.addEventListener('DOMContentLoaded', function () {
 
  document.querySelector('#check').addEventListener('click', function () {
	  if (document.getElementById('passwd').type == 'password' ) { 
	    document.getElementById('passwd').type = 'text';
	    this.innerText = 'Passwort verstecken'; 
	  }
	  else {
	    document.getElementById('passwd').type = 'password';
	    this.innerText = 'Passwort sichtbar machen'; 
	  }
  });
 
});

</script>  

</head>

<body>
<h1>Passwort sichtbar machen</h1>

  <form>
    <label for="email">E-Mail</label>
    <input type="email" id="email" required>
 
    <label for="passwd">Passwort</label>
    <input type="password" id="passwd" required autocomplete="off" spellcheck="false">
 
    <button type="button" id="check">Passwort sichtbar machen</button>
    <button class="ok" type="submit">anmelden</button>    
  </form>

<p>Damit niemand bei einem Blick über die Schulter das Passwort erfahren kann, zeigen Passwortfelder nicht die Eingabe, sondern nur Platzhalter an.</p>
<p> Oft ist man jedoch allein zu Hause, möchte sich aber <strong>vor</strong> dem Absenden vergewissern, ob die Eingabe richtig war.</p> 

</body>
</html>