views:

145

answers:

2

Hello,

I have html like this

<td>
<textarea name="foot"><?=$e->foot;?></textarea>
Preview:
<div><?=$e->foot;?></div>
</td>

So how can i collect the data of textarea and load it into the div next to it with jquery. Also i have lot of textareas like this, so how is it possible to load the text entered with onchange to its next div.

Thank You.

+1  A: 
 $(document).ready ( function() {
            $("textarea[name='txt']").bind ( "keydown focus" , function () {
                $(this).next().text ( $(this).val() );
            });
        });

or if the div is not the next element then provide a class name for it and use the code

$(document).ready ( function() {
     $("textarea[name='txt']").bind ( "keydown focus paste" , function () {
       $(this).siblings(".divClass").text ( $(this).val() );
     });
});
rahul
How to load it in the div?
Shishant
The statement $(this).next().text ( $(this).val() ); loads the value of textarea to the adjacent div[next element].
rahul
A: 

Its a little dirty but it works

 <div class="entry"> 
    <textarea class="foot"> my text</textarea>
    <div class="enterhere"> </div>
 </div>

 $(".foot").change(function() {
        $(this).parent().children(".enterhere").text($(this).val());

    });
Markus
I would do .parents(".entry").find(".enterhere") Slower but more resistant to HTML tweaking
Vincent Robert