views:

57

answers:

4

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?

+3  A: 

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
Indeed. Somewhat non-standard.
spender
Wouldn't this be better if the polling is mapped to a onkeyup() instead?
Razor Storm
@Razor Storm Sure, but I never mentioned what the polling may be attached to.
alex
What I meant was that if you map it to an keyup event, you don't have to set an interval. This would cause the function to be more responsive, and the code to be more efficient overall.
Razor Storm
A: 

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

Itay Moav
I'm not sure if these are fired for stored data
Tom Gullen
easy to test it, right?
Itay Moav
+4  A: 

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
A: 

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