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 danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ONKEYUP and ONCHANGE events

Status
Not open for further replies.

ruffy

Programmer
Oct 1, 2003
72
US
As a user types into a textfield, another field generates a new number to reflect each additional letter. For example, "c" yields 1, "ca" yields 3 and "cat" regenerates the number field to, say, 9. The user sees this update as he types in his string. For this we use the ONKEYUP event.

Our problem comes when the user "pastes" a string into the text field. Pasting doesn't trigger the ONKEYUP event. Were we to use ONCHANGE, we'd lose the letter-by-letter update-and-show-number feature. That's because ONCHANGE
only gets the input once the entire string is entered.

Can you suggest code that incorporates the benefits of both the ONKEYUP and the ONCHANGE events, so we could still offer letter-by-letter updates and, in the event of a paste, update the number field based on the entire string?
 
If I am understanding your situation correctly, it sounds to me like simply having both events defined should accomplish your goal; i.e., onkeyup will fire on keystrokes and onchange will fire when the control loses focus after a paste.

Does this not acheive what you are looking for?

<geek/>
 
Thanks! It's probably simple but how do I combine the two to work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top