The code below works fine, it changes the type of password to reveal the input as text. The prolem appears when adding a name attribut to "password" in order to retrieve data from $POST in php. I thought there might be a way to get the data on serverside without a "name", but my reasearch showed that without a "name" attribute no data can be retrieved.
Question: How to bring in the name attribute and keep my functionality?
<div>
<label for="password">Passwort (8 min. pls. )</label>
<input type="password" id="password" minlenght="8" required>
</div>
<div>
<label for="anzeigen">Passwort anzeigen</label>
<input type="checkbox" onclick="anzeigen()" >
</div>
<div>
<input type="submit" id="mitmachen" value="mitmachen">
</div>
</form>
<script>
function anzeigen() {
var x = document.getElementById("password");
if (x.type === "password") {
x.type = "text";
}else {
x.type = "password";
}
}
</script>