Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto select the state from an option list when using address autofill

I made an form in HTML and the autofill feature on Chrome successfully fills in the street address, city, and zip. If I leave the "state" input with type="text", then it gets autofilled successfully as well. However, if I use a select/option dropdown list, then it does not get autofilled.

For the options, I tried using state abbreviations for the value like:

<label>
    <select>
        <option value="AL">Alabama</option>
        <option value="AK">Alaska</option>
    <select>
    State
</label>

and I tried using the state name for the value:

<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>

And neither one works.

Is there a way to get Google Chrome's autofill to automatically select a state from a dropdown list when it is auto-filling the address?

Notes:

  • I'm interested in getting it to work for any other browsers/extensions that auto fill addresses for users, but I've only tested in Chrome.
  • a javascript solution would be acceptable, but it's not what I'm wanting. But, no jquery.
like image 368
Reed Avatar asked Oct 19 '15 21:10

Reed


People also ask

What is autofill CSS?

The :autofill CSS pseudo-class matches when an <input> element has its value autofilled by the browser. The class stops matching if the user edits the field.


1 Answers

<select autocomplete="state">

will work too

like image 63
Devin McQueeney Avatar answered Sep 22 '22 00:09

Devin McQueeney