Its because you are invoking the "onKeyUp" event that the function call starts immediately.
Well, "OnKeyUp" is the right event, but how your code will come to know that user has finished entering the text ?
For that you need to track a specific key. If that key is hit, that means user has finished entering the text. Normally we call this specific key as the "Enter key".
So, onkeyup, you track which key was pressed. If its "Enter key", then only you start processing your code.
something like -
Code:
var key = event.which || event.keyCode;
if(key == 13) { // 13 is the keycode for enter key
// your piece of code here...
}
Hope it helps you out...
Regards,
Niral Soni