jQuerybeast
jQuerybeast

Reputation: 14500

jQuery: Carrying input text from tab to another tab

I have an html with few tabs. In all of tabs there's an input type=text. If i type something in the input on tab1, how can it be typed to the rest of the inputs in the other tabs too?

I would guess its something similar here in stackoverflow when you ask a question and you get a preview box underneath but instead that would be an input too.

If input id's are input1, input2 and input3 can someone show me a quick way if possible?

Thanks alot

Upvotes: 0

Views: 762

Answers (3)

mcgrailm
mcgrailm

Reputation: 17638

I would use a class on the inputs

$('.group_input1').change(function(){
     $('.group_input1').val(this.value);
});

Upvotes: 2

Tim Joyce
Tim Joyce

Reputation: 4517

$('#input1').blur(function(){
    if ($('#input1').val() != '')}
        $('#input2').val($('#input1').val());
        $('#input3').val($('#input1').val());
    }
});

Something like that should work... but you might have to check if input on tab 2 was filled in first.. If that is the case then we can rework this code.

Upvotes: 0

Ender
Ender

Reputation: 15221

$('#input1').blur(function() { $('#input2,#input3').val(this.value); });

Here's a working demo: http://jsfiddle.net/Ender/C5L7W/

I've chosen blur as the update event, because this event must occur when switching tabs (as the source textbox will lose focus), and it involves the fewest updates to other inputs compared to using something like keyup, keydown, or keypress.

Upvotes: 2

Related Questions