12

I was struggling for a while on the html5 autocomplete feature of Chrome. I had a form like this

<form>
<input name='myname' type='email' autocomplete='on' />
<input type='submit' value='Submit!' onclick='transform_and_post_data();return false;'/>
</form>

When using Firefox and returning to this form autocomplete works fine. But not with Chrome (versions 26 to 30 at least). I finally found that autocomplete saving of a form is done only when calling the GET or POST default action of the form (here prevented by the return false). So I found a work around that fixes it in some situations :

 <form method='post' action='myaction'>
 <input name='myname' type='email' autocomplete='on' />
<input type='submit' value='Submit!' onclick='transform_data();'/>
</form>

This works well as long as I do not need to post my form data through an XhttpRequest. Does any one knows a trick to make Chrome autocomplete forms with XHRs?

Is it a known bug of Chrome? (as Firefox works as expected)

Note : autocomplete='on' should be useless because it is the default behaviour of an input

frank
  • 438
  • 1
  • 5
  • 19
  • I can't add comments, so I have to add an answer, but to as why an id attribute is needed is because the browser needs to know what field you are actually trying to type in, without an id, it has no idea what should be pre-populated. – Narsters Jul 11 '18 at 20:31

2 Answers2

14

Chrome will only save the autocomplete information on submit. There are some workarounds detailed here: Trigger autocomplete without submitting a form

Community
  • 1
  • 1
Tom
  • 688
  • 13
  • 29
6

Please provide ID to your input variable

<form method='post' action='myaction'>
 <input name='myname' type='email' id="myname" autocomplete='on' />
 <input type='submit' value='Submit!' onclick='transform_data();'/>
</form>

Then it should work, without id it wont work