Click here to Skip to main content
15,887,256 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone tell me why we need to use values of autocomplete other than on/off (like given-name, family-name, new-password,etc.) because i found out that form will be autofilled only when name attribute form exactly matches perviously stored value having same name attribute (e.g. if my form has name="fname" than autocomplete only work when contains previously stored data in which fname="naresh" and it will suggest naresh) also if name attribute not present id attribute should be same. this will happen when autocomplete=on and works same if autocomplete=other_value_except_off then why we use these values (given-name,etc.).

What I have tried:

I have created two files input1.html and input2.html. autocomplete only works if name attributes are same no effect of autocomplete - input1.html:

HTML
DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <form>
    <label for="firstname">first name: </label><input type="text" id="firstname" name="fname" autocomplete="given-name">
    <br>
    <label for="lastname">last name: </label><input type="text" id="lastname" name="lname" autocomplete="family-name">
    <input type="submit">
  </form>
</body>

</html>
input2.html:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <form>
    <label for="firstname">first name: </label><input type="text" id="firstname" name="firstname"
      autocomplete="given-name">
    <br>
    <label for="lastname">last name: </label><input type="text" id="lastname" name="lastname"
      autocomplete="family-name">
    <input type="submit">
  </form>
</body>

</html>

here if i filled form in input1.html and then open input2.html - no suggetions but if i changed name of input2.html to fname and lname then i will suggestions. what is the role of autocomplete here. i better use autocomplete=on then why we need other values i am using this in google chrome
Posted
Updated 14-Feb-24 6:45am
v2

1 solution

"on"
The browser is allowed to automatically complete the input. No guidance is provided as to the type of data expected in the field, so the browser may use its own judgement.
If you just use "on", then the browser has to guess what sort of data you're expecting in the field.

If you use a more specific value, then you're explicitly telling the browser what sort of data is in the field, so it doesn't need to guess.
 
Share this answer
 
Comments
Naresh Lohar 14-Feb-24 7:41am    
then why my second file not showing me suggestions? please explain.
Richard Deeming 14-Feb-24 7:57am    
Perhaps you don't have any autocomplete entries for the specified data types?

I've just checked: Firefox doesn't offer address autofill outside of the US, and Chrome doesn't separate the components of your name in the saved addresses. So it's quite likely that your browser doesn't have a "given name" or "family name" to suggest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900