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?
Asked
Active
Viewed 977 times
8
-
What event are you using to detect the user entering the data? – a_m0d Jul 08 '10 at 01:06
-
5How do users without Javascript get to log in? – spender Jul 08 '10 at 01:09
-
@spender The only way I could see it working for non JS users would be to disable the button only on DOM ready or similar. – alex Jul 08 '10 at 01:19
4 Answers
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
-
-
Wouldn't this be better if the polling is mapped to a onkeyup() instead? – Razor Storm Jul 08 '10 at 16:19
-
@Razor Storm Sure, but I never mentioned what the polling may be attached to. – alex Jul 08 '10 at 23:41
-
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 Jul 09 '10 at 00:54
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
-
-
This does not seem to work; at least when utilizing jQuery .change() – streetlight Nov 02 '12 at 14:25
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