views:

28

answers:

1

Hi

If am entering some values in text box it should be simultaneously displayed in other text box using html and js in the same page.

That is if i enter test in text box then the other text box should contain the alphabet test immediately.

Is that possible. If yes how?

kindly clarify.

thanks in advance

+4  A: 

Use the onkeydown event, combined with a timer that will execute immediately afterwards:

textbox1.onkeydown = function () { 
    window.setTimeout(function () { textbox2.value = textbox1.value; }, 0);
}

Example

For Opera, you will need to use onkeypress to capture repeated input (holding the key down).

Andy E
Do you need the `setTimeout` there? (I’m sure you do, I just can’t see why off the top of my head.)
Paul D. Waite
@Paul: events that can be cancelled fire *before* their action, so not using the timer would result in the previous value being copied to the other text box.
Andy E
thanks andy.. working cool. this is what i exactly need
Fero
@Andy: aha! Gotcha.
Paul D. Waite