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
2010-07-08 01:06:41
Indeed. Somewhat non-standard.
spender
2010-07-08 01:07:43
Wouldn't this be better if the polling is mapped to a onkeyup() instead?
Razor Storm
2010-07-08 16:19:03
@Razor Storm Sure, but I never mentioned what the polling may be attached to.
alex
2010-07-08 23:41:46
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
2010-07-09 00:54:41
A:
Haven't tested it, but you can use the onchange event on the text fields.
Itay Moav
2010-07-08 01:08:23
+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
2010-07-08 01:11:29
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
2010-07-08 01:38:18