Forum Moderators: open

Message Too Old, No Replies

Updating text on the fly

         

Crump

3:07 pm on Jun 14, 2006 (gmt 0)

10+ Year Member



I have a form with a text input. I would like to update a div on the same page with the contents of that form. I would like to do this on-the-fly, meaning each time the user types a letter in the div updates (using innerHTML I guess?).

Right now I have onchange, but that only updates the div after leaving the textbox (bluring).

Any ideas? Thanks.

Fotiman

3:14 pm on Jun 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would try the onkeypress event instead. From the HTML specs, section 18.2.3 Intrinsic Events [w3.org]:


onkeypress = script [CT]
The onkeypress event occurs when a key is pressed and released over an element. This attribute may be used with most elements.


onchange = script [CT]
The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus. This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA.

adni18

5:00 am on Jun 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



onkeydown and onkeyup also work, you can make it so it starts a setInterval loop that auto-updates the div, say, every 10 milliseconds, then that loop is killed with the onkeyup, so that holding down a letter (like hhhhhhhhhhhhhhhh) won't be delayed until the user lifts the key.