1

I'm dealing with two text box - using jQuery I want that every time the user updates the value in the first box , the same value will apear in the second box.

​<input type="text" class="pack"/ > ​<input type="text" class="pack2"/>​​​​​​​​​​​​​​​​​​​​​​​​ ​$(".pack").keypress(function(){ $(".pack2").val($(this).val()); });​​​​​ 

The problem is that if I type a letter in "pack" , it won't appear in "pack2" right away - I'll have to type another letter, and then the first letter will appear in pack2

You can check the fiddle - http://jsfiddle.net/itamarperetz/jGXyA/

What can I so pack2 will be updated right away?

Any suggestion will be helpful, Thanks in advance

0

4 Answers 4

2

Try changing the keypress event to keyup.

​$(".pack").keyup(function() { $(".pack2").val($(this).val()); });​​​​​ 

jsFiddle demo

Sign up to request clarification or add additional context in comments.

Comments

1

That's because keypress is fired before the character is actually added to the input-field. Try using keyup instead, which is fired after the character is added to the input-field.

Comments

1

Check out this working answer.

You should use keyup rather than keypress.

Check out the API here.

Comments

1

Use keyup event

$(".pack").keyup(function(){ $(".pack2").val($(".pack").val()); });​ 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.