Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Autofill and Javascript triggered events

Tags:

One of our users just brought up the fact that their browsers Autofill doesn't cause JS onChange events to fire; this causes a problem with user registration for us.

Is this by design? Is there a way to work around it?

like image 248
Glen Solsberry Avatar asked Feb 08 '11 20:02

Glen Solsberry


People also ask

How do I turn off autofill?

On your Android device, open the Chrome app. Then, tap on the three-dot menu button at the top-right corner and select “Settings” from the drop-down menu. 2. Now, just like on the desktop version, you have to disable autofill individually for all three categories – Passwords, Payment methods, & Addresses and more.

How does auto fill work?

In web browsers, autofill is a feature that automatically populates form fields with previously-entered information, such as passwords, addresses, and credit card data. For this sensitive information to be stored, the autofill feature must be enabled and have appropriate permissions.

How do you autofill a website?

Open Chrome and click on your profile icon in the top-right corner. Select either Payment options or Addresses and more to see the information autocomplete is currently using. Toggle the Save and fill addresses or Save and fill passwords switch depending on whether or not you want to use autocomplete.


2 Answers

One solution I have been using occasionally is to check whether the value of the field/input/select differs from it's defaultValue. defaultValue would be the value that was originally in the markup, and value is the current value aka selected or entered value. This would probably differ even though the form was autopopulated.

If you want to turn off autofill altogether, it might be wise to add autocomplete="off" on fields that are directly connected to your logic.

like image 166
jishi Avatar answered Sep 25 '22 10:09

jishi


If you want to get the autofill behaviour but change the styling, maybe you can do something like this (jQuery):

$(window).load(function(){  
  if($('input:-webkit-autofill')){   
    $('input:-webkit-autofill').each(function(){
      //put your conditions here 
    });   
    // RE-INITIALIZE VARIABLES HERE IF YOU SET JQUERY OBJECT'S TO VAR FOR FASTER PROCESSING 
}});
like image 23
Lavlesh Mishra Avatar answered Sep 24 '22 10:09

Lavlesh Mishra