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?
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.