8

I have a website that detects when a user name and password has been entered, then enables the login button. The problem is if the browser enters the user name and password that it has remembered then the login button is never enabled. Is there a way in JavaScript to detect a browser entering this information?

Tim
  • 81
  • 1

4 Answers4

5

You could poll for it with setInterval(), but why would you want it to be disabled before the details are entered anyway?

It doesn't seem to be a widespread practice.

alex
  • 479,566
  • 201
  • 878
  • 984
4

Alternatively, you could keep the button enabled and check for a non-blank input when it is pressed. This would be more standard, as others have indicated.

harpo
  • 41,820
  • 13
  • 96
  • 131
  • it's interesting how fast things change. I'm run into this same issue, and now it seems to be common practice to disable login buttons when the credentials have not been entered. – ILikeTacos Jul 19 '16 at 21:18
0

Haven't tested it, but you can use the onchange event on the text fields.

Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
0

First as others mentioned I'm not sure why you would not have enabled as default. But, here is what you would need to do. When the page loads just check to see if there is anything in the fields. Sometimes the browser inputs the login info, when the fields have focus, but I assume if it has focus your script may detect the input.

window.onload=function(){
  var txt=document.getElementById('username');
  if(txt!==''){showSubmit();}
  //if you have a preset value you can always do txt!=='username'
}
qw3n
  • 6,236
  • 6
  • 33
  • 62