Trying to avoid any browser's stuff about autocomplete
, password suggestion
etc.
And at the same time keep the show/hide letters
functionality.
The idea is to keep password
as a variable, regardless of show/hide
state.
In the code below problem is if user press Backspace
or Delete
key. In that case the whole concept crushes down.
Any help?
var pass = "";
$('#inpass').on('input', function(){
if(!$('#checka').is(':checked')){
let a = $(this).val();
let b = a.substr(-1);
pass += b;
let c = a.replace(/.$/, '*');
$(this).val(c);
console.log(pass);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type='text' id='inpass' maxlength='25' placeholder='password' title='password' autocomplete='off'>
<br><br>
<input type='checkbox' id='checka'>
<label for='checka' id='labela'>show letters</label>