Doctor
Doctor

Reputation: 57

Cant get value of text area

I have used knockout and got these back from my ModelView template ...

<div class="both">
    <td>
    <h3 data-bind="text: MyText"> What type of fruit is healthy ?</h3>
    <textarea data-bind="attr:{id: Question}" class="my-response" id="1"> this is my text area value </textarea>
    </td>   
</div>

<div class="both">
    <td>
        <h3 data-bind="text: MyText"> What type of Veg is healthy ?</h3>
        <textarea data-bind="attr:{id: Question}" class="my-response" id="2"> this is my text area value</textarea>
    </td>
</div>

I want to get the value of text area and this is not working..

$('.both').each(function() {
 alert($('.my-response').val());
});

how can I do that?

Thanks

Upvotes: 0

Views: 312

Answers (3)

Doctor
Doctor

Reputation: 57

This worked best !

$(function(){

$('.my-response').each(function () {alert($(this).val());});

});

Demo

Upvotes: 0

Nir
Nir

Reputation: 356

you can try this one as well

$(document).ready(function(){
    $('.my-response','.both').each(function(){alert($(this).val())});
});​

here is the demo

Upvotes: 1

Shyju
Shyju

Reputation: 218852

Try this

$(function(){

   $('.both').each(function(index,item) {
       var v= $(item).find('.my-response').val();
       alert(v);
   });        

});

Working sample : http://jsfiddle.net/2CGWG/3/

Upvotes: 2

Related Questions