PlutoPlanetStar
PlutoPlanetStar

Reputation: 1

Javascript - Text field is not supposed to auto fill with the saved username

A html input field is auto filled with a username saved in the browser sign in form. Two months ago, this resolved the issue with this code.

<input style="display:none" type="text" name="fakeusernameremembered">
<input style="display:none" type="password" name="fakepasswordremembered">

But I believe this week, chrome had an update and it broke the fix. This fix works with firefox, but it looks like chrome has gotten smarter and has turn my fix into a problem-unresolved. Any ideas on how to fix this?

Upvotes: 0

Views: 1513

Answers (5)

Genesha Irzan Pratama
Genesha Irzan Pratama

Reputation: 61

$(document).on('focus,click', '#input_pass', function(e) {
    $("#input_pass").attr("type", "text");
    $("#input_pass").attr("type", "password");
});

this how 'play it'

Upvotes: -1

PlutoPlanetStar
PlutoPlanetStar

Reputation: 1

Thank you for your answers. I tried them all. I got it working. I ended up using this:

$('#selectedID').append('<input style="opacity: 0;position: absolute;">');
$('#txtselectedID').append('<input type="UserName" style="opacity: 0;position: absolute;">');

But for another page, I used this: and it worked when this one didn't.

    jQuery(document).ready(function ($) {
    //======fix for autocomplete
    $('input, :input').attr('readonly', true);//readonly all inputs on page load, prevent autofilling on pageload

    $('input, :input').on('click focus', function () { //on input click
        $('input, :input').attr('readonly', true);//make other fields readonly
        $(this).attr('readonly', false);//but make this field Not readonly
    });
    //======./fix for autocomplete
});

Upvotes: 0

CptKicks
CptKicks

Reputation: 441

Are you talking about autocompletion?

If yes, use the 'autocomplete' attribute and set it to 'off'.

More info here https://www.w3schools.com/tags/att_input_autocomplete.asp

Later edit: This won't work on all the browsers for all the types of inputs. Apparently using autocomplete on the form element is widely supported. https://caniuse.com/#search=autocomplete

<form autocomplete="off">
 <input autocomplete style="display:none" type="text" name="fakeusernameremembered" autocomplete="off">
 <input style="display:none" type="password" name="fakepasswordremembered" autocomplete="off">
</form>

Upvotes: 0

Angel
Angel

Reputation: 114

style="display: none;" will 'hide' the element from the DOM.

You should use the autocomplete HTML attribute instead.

<input autocomplete="off" type="text" name="fakeusernameremembered">
<input autocomplete="off" type="password" name="fakepasswordremembered">

More about autocomplete attribute here.

Upvotes: 1

keidakida
keidakida

Reputation: 741

Yes, the method you used for fake inputs so that autocompletes won't fill is right. Use autocomplete="nope" for the input fields of username and password. That might solve the issue sometimes.

Upvotes: 0

Related Questions