How to check position of cursor blinking on text box

I am working on Tag System and i’m copying Declicious Tag Autocomplete
style.
I thought that i have to check where is the position that cursor blink
but i don’t know how to do that.

i Can do it already , I’m sorry i should put this on rails section
and with my low basic, i don’t know that there is such function as token