Home » Jquery » javascript – Input type Password not working autocomplete="off" using Angularjs

javascript – Input type Password not working autocomplete="off" using Angularjs

Posted by: admin February 22, 2020 Leave a comment

Questions:

I have used autocomplete="off" but not working in password input please check below atteched my demo code.

  <form name="testfrm" ng-submit="test(testfrm)" autocomplete="off">
       <input type="password" id="passwordFiled" name="test" autocomplete="off"  required>
       <button type="submit" class="btn"> test </button>
  </form>

Please let me know how to disabled autocomplete for password filed

How to&Answer:

You can add a name-changer function for the password field, it can be a possible solution, here’s the code I tried:

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script>

            // Returns random string based on 32 different characters and 4 dashes ("-")
            function string_generator() {
                var str = function() {
                   return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
            };
            return (str() + str() + "-" + str() + "-" + str() + "-" + str() + "-" + str() + str() + str());
        }

        $(document).ready(function() {
            $("#passwordField").attr("name", string_generator());
        });
        </script>
    </head>

    <body>
        <form name="testfrm" ng-submit="test(testfrm)">
            <input type="password" id="passwordField" name="test" autocomplete="off" required>
            <button type="submit" class="btn"> test </button>
        </form>
    </body>
</html>

Let me know if it works (if it doesn’t work, please check the password-field id, because in my code is “passwordField“, while in your is “passwordFiled“)

Anyway, if you need the original name test as the url variable, this answer is supposed to be useless