Get current word being typed in a text input field

D

darius

Hello

I'm doing a bit of AJAX auto completion. The text field is a string of
tags separated by spaces. My problem is I need to know which is the
current word that I need to autocomplete.

When the user starts typing, I can assume it's the last word that needs
to be autocompleted: ([] is the caret)

pictures fun[]

But when she backs up to edit or insert another word

pictures anim[] funny

here I need to know I'm autocompleting 'anim'. How do I determine that?

thanks
 
D

Dan Rumney

Hello

I'm doing a bit of AJAX auto completion. The text field is a string of
tags separated by spaces. My problem is I need to know which is the
current word that I need to autocomplete.

When the user starts typing, I can assume it's the last word that needs
to be autocompleted: ([] is the caret)

pictures fun[]

But when she backs up to edit or insert another word

pictures anim[] funny

here I need to know I'm autocompleting 'anim'. How do I determine that?

This page http://blog.vishalon.net/Post/57.aspx talks about getting
and setting the caret location in a textarea.

Then, take the substring of the entry field from the start of the
string to the position of the caret.

Then, perform a split on the space character

Then, take the last item the the resulting array.

That's one way to do it... but what happens in the following scenario?

"pictures anim [] funny"

You need to decide what you want to happen in this case before you can
decide how to implement it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top