Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can we get a "true" onchange() handler? 1

Status
Not open for further replies.

twrofpwr

Programmer
Jun 11, 2005
2
CA
I am pulling my hair out with this. I am tryign to develop a mechanism of executing a function everytime a text box field is changed, from every single keystroke typed. Is this possible?

Thanks,

Jeff
 
Jeff,

FYI - the onchange event doesn't fire until the textbox loses focus.

There's always a better way. The fun is trying to find it!
 
So is there an easy way to do this? after i browsing many posts i only way i find is that to stored previous value in temp variable then everytime onkeyup & onmouseup(incase user use mouse to make change) we go to the same function and check the current value against the previous value. I think this should work but it seems kinda messy especially if i want to implement this for more than just one textbox.
 
dieyoudie, you may not have to keep track of the values.
It depends on what you are testing for but since you can only type one key at a time you only need to check the last character entered and therefore do not have to keep track of every current value in every field.

The one exception I can think of is if someone pasted information into a field. You can probably trap an event like that though which would let you know if you needed to test just the last character or all characters.

Now, one last thought. If you use onkeyup, you could check the entire string every time onkeyup is detected.
Sure it is technically cumbersome to do your checks at every single keystroke as they potentially type in a lot of info. It depends really on how much testing you are doing.
If you just test for invalid characters then the check is very fast especially if the fields are not real long.
Control should get back to the field before the client hits the next key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top