开发者

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 ?

T开发者_如何学Chanking in Advance

Girish


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.


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() );
});


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

HTML:

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

JavaScript:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜