The problem was that the form tag didn’t have method="POST" on it.
After Googling the message, I found a bug report, and one of the comments mentioned method="POST".
I added method="POST", and voila! Auto-fill works.
In some cases you may also need to add an action if the form doesn’t have one. action="https://stackoverflow.com/questions/8715000/javascript:void(0)" works.
Note: Auto-fill seems to trigger the onchange event.
Note 2: As for how the browser knows what field is what, see this question: How to trigger Autofill in Google Chrome?