Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] When should an "onChange" event actually change?



 On 8/17/2010 2:51 PM, Dave M G wrote:
TLUG,

Javascript type question here, though this might have to do with browser
differences as well.

I've got a form that has text fields to enter in a username and
password, and a submit button. I'm using Javascript to evaluate the
content of the fields, to make the submit button be greyed out until
certain criteria are met. For example, ensuring the text is more than 6
characters and so on. When the two fields are filled in and pass all the
criteria, the submit button turns green.

I use the "onChange" event to call the necessary functions that do the
evaluating and change the button style properties.

Works basically fine. However, the timing is a little off. If I fill in
both fields correctly, the button only turns green if I shift focus away
from the text fields. So, I'll type in a user name, switch to the
password field and type that in. When I type in the complete password,
the button isn't green yet. If I click somewhere else on screen, *then*
the button turns green.

It's as if "onChange" is behaving like what you might call a "mouse
out", or an "onChangeOfFocus". I thought "onChange" mean whenever you
changed the content of the text field.

It seems to me I've been to sites where the Javascript evaluates the
content of a text field as it is typed.

Am I not understanding the expected "onChange" behaviour, or is it that
I need to do something else, or in a addition, to get more immediate
feedback from my Javascript?

You might consider using onkeyup instead. It'll evaluate the fields each time a key is released, such as when the user enters their password.

You probably know this but it's worth repeating, Javascript is fine for enhancing usability but should never be relied on for validation. It's trivial to submit that form with invalid data even if your Javascript is solid and the submit button is disabled.

--KyleHase


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links