Girish
Girish

Reputation: 893

How to populate a textarea(say id1) when user types in a different textarea(say id2) using php and javascript

I have 2 textarea html elements say id1 and id2. When I type in id1 the content of id1 should also be displayed in id2.
Can anyone suggest me php code or jquery plugin or javascript to complete this process ?

Thanking in Advance
Girish

Upvotes: 1

Views: 442

Answers (3)

Damb
Damb

Reputation: 14600

Simple way how to do it:

$(document).ready(function(){
    $('.tb1').keyup(function(){
        var content = $('.tb1').val();
        $('.tb2').val(content);
    });
});

And HTML:

<textarea name="Text1" class="tb1" ></textarea>
<textarea name="Text2" class="tb2" ></textarea>

Working example at jsfiddle.net.

Upvotes: 1

Billy Moon
Billy Moon

Reputation: 58601

with jQuery: http://jsfiddle.net/EjmtY/

HTML:

<textarea id='id1'></textarea>
<textarea id='id2'></textarea>

JavaScript:

$('#id1').keyup(function(){
    $('#id2').val($(this).val())
})

Upvotes: 0

mcgrailm
mcgrailm

Reputation: 17638

like this

the html

<input type="text" id="box_1" />
<input type="text" id="box_2" />

the jQuery

$("#box_1").change(function(){
   $('#box_2').val( $(this).val() );
});

Upvotes: 0

Related Questions