lyhong
lyhong

Reputation: 947

Cannot change input value while setting default value in jquery

I am trying to set default value to an input from another I am entering. However, I can enter data into that box. But I cannot get new value I entered when I submit. Please see my code below:

$('.input1').bind('keyup blur', function(){
    $('.input2').val($(this).val());
});

Upvotes: 1

Views: 600

Answers (1)

Ionică Bizău
Ionică Bizău

Reputation: 113355

Use on("input", function () { ... }), instead:

$('.input1').on('input', function(){
    $('.input2').val($(this).val());
});

JSFIDDLE


Also, see this thread about the difference between input and change.

Upvotes: 3

Related Questions