5

Is there anyway I can detect the autofill BEFORE the user selects an option from the dropdown?

enter image description here

Expected: 400010 as seen.

Currently I have:

$('input').on('input paste change keyup', function(event) {
    if(event.type=='input'){
      console.log( $(this).val() ); 
    }
});

.. and it works AFTER the user has made a selection, but not before as seen in the above screenshot.

eozzy
  • 66,048
  • 104
  • 272
  • 428
  • Possible duplicate ? : http://stackoverflow.com/questions/11708092/detecting-browser-autofill – DarkHorse Dec 19 '14 at 06:28
  • @DarkHorse No, tried that, none of those solutions work. – eozzy Dec 19 '14 at 06:29
  • Just to clarify, change *is* detected AFTER the selection is made and the field is still in focus, but I need text changes DURING the selection when the user hovers over the options. – eozzy Dec 19 '14 at 06:30
  • 4
    you don't have access to users stored autofill data for fairly obvious security reasons – charlietfl Dec 19 '14 at 06:37
  • 3
    Unfortunately, this is not possible.... :( Here is a report on the [issue](https://code.google.com/p/chromium/issues/detail?id=352527#c15) where they say `We do send a change event when a user chooses to autofill. I think the "bug" you're observing is that username/pw fields aren't really autofilled until the user interacts with the page (for security/privacy reasons).` Hope this helps. – Dom Jan 21 '15 at 06:04
  • how the suggestion list is populated ? is it u populating the suggestions or ur relying on the browser remember history case ? if its the browser doing that it's not guaranteed to work for all users.. specially when they turned it off in their preferences :) – Arkantos Jan 24 '15 at 07:57
  • Take a look at the accepted answer to this question: http://stackoverflow.com/questions/8548533/any-event-triggered-on-autocomplete Maybe that can help you in finding out, if there's an event fired at all and if that event can tell you the value that is being autofilled. – mmgross Jan 27 '15 at 04:00
  • You will never achieve that as this is really very browser specific. The value isn't really there, so nothing in DOM changed. You can remove the bounty off this question, it'll never be answered. – jPO Jan 27 '15 at 15:46

2 Answers2

6

Read this article, they go in-depth on detected auto-fill events. The problem is that not all browsers support auto-fill events, however I don't think any would be foolish enough to support this feature before the user makes a selection. Think about this: if they supported auto-fill events before a selection was made it would be extremely simple to steal peoples passwords, zipcodes, credit cards, etc. Since you could just send an AJAX request containing the auto completed information in each of these fields, regardless of whether the user actually selected them.

Sorry, if I couldn't be of more help.

Alec
  • 942
  • 5
  • 11
-1

try like this:

$(document).ready(
function (event) {
    $('.ddClass').on('mouseenter', 'option', function(e) {
    $("#zipcode").val(this.value);

);
});

//where .ddClass is the class of dropdown option

Semicolon
  • 1,847
  • 2
  • 15
  • 19
  • Isn't this the same as: `$('input:not([type=password]), textarea, select').on('hover', function(event) { if(event.type=='hover'){ console.log( "hover: " + $(this).val() ); } });` – eozzy Jan 21 '15 at 05:47
  • it doesn't work though. Please see this screencast: https://www.dropbox.com/s/bgvb0i0x4u8urpi/2015-01-21_1119.swf?dl=0 – eozzy Jan 21 '15 at 05:51
  • dropbox is blocked at my end – Semicolon Jan 21 '15 at 06:17