1

I have a password input element and and some radio buttons on an HTML form -- a login form for a web site. When the user enters text in the password input box, it should select one of the radio buttons. I do this by selecting the radio button in the password input's onKeyUp handler.

However, some users use their browser's password save feature, which automatically fills in the password (and other text input fields) on the form. However, at least on Chrome and Firefox, the password auto-fill does not save the state of the radio buttons on the login form.

I need to select this radio button when the browser auto fills the password input, in the same way I select it when the user types in the password input.

Is there another event besides onKeyUp that will fire when the browser fills in the text? If not, is there some other way I can accomplish this?

Goal: Select a radio button if a password is entered in a password input, whether it's entered by keyboard or filled in by browser.

1
  • 1
    I think that you should have an event (onchange perhaps) on the input and also have something like if(input has something) $('.radio1').attr('checked', true); when the page loads Commented Jul 29, 2013 at 2:47

1 Answer 1

2

You can trigger the keyup event when the page loads, so it will do your work if some text is been written on that filed by the browser.

setTimeout(function() {
     $('#your_field').trigger('keyup');
},250);
Sign up to request clarification or add additional context in comments.

2 Comments

That almost works except some browsers auto fill after onLoad. I solved it (I guess) by creating a 250ms one-shot timer in onLoad that selects the radio button if the input contains text. It's unfortunate that they didn't think about browser auto-complete when they came up with the script event system.
Thanks Jason, i have updated my code as per your modification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.