views:

57

answers:

1

On my page I have a textarea where users can enter a list of items, items being separated by a newline.

I would like to process the user's input without him/her having to press a submit button. ("Process" means send the information the user entered to the server and update other elements on the current page.) I thought of two days of doing this:

1- Install an event handler for keypress events and, when I get an event for the Enter key being pressed, process the line the user just completed. (Getting cursor position info as done here.) This has the disadvantage of not handling copy-pasting into the form. (And, if I understood correctly from browsing Stack Overflow, support for handling paste events is not great even among most common browsers, right?)

2- Periodically process the contents of the textarea by using setInterval(). I am already using a setInterval() on the page to implement the unique URLs pattern, so if I could I would avoid that.

Are there better ways to achieve this?

+2  A: 

There is also an "onchange" event for a textarea. You can use it to detect any changes, including paste or magic inserts.

alemjerus
@alemjerus: thanks, that is helpful! I will listen for that event.
laramichaels