Reputation: 85
Reading with val() doesn't work and I'm getting back only an empty result. How can I read the textarea for updating a db with ajax?
var k = jQuery.noConflict();
k(document).ready(function(){
k('.portfolio_classic_icon_content_middle').on('keyup', function(){
var message = k('#gallery_images_comment').val();
console.log(message);
});
});
My html code with the textare looks like this:
<div class="portfolio_classic_icon_content_middle">
<textarea name="comment" id="gallery_images_comment" form="usrform">This is the text loaded</textarea>
</div>
Upvotes: 2
Views: 93
Reputation: 22323
Must define somewhere k
is equivalent to $
before use it.
var k = $;
k('.portfolio_classic_icon_content_middle').find('#gallery_images_comment').on('keyup', function(){
var message = k(this).val();
console.log(message);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="portfolio_classic_icon_content_middle">
<textarea name="comment" id="gallery_images_comment" form="usrform">This is the text loaded</textarea>
</div>
Upvotes: 2
Reputation: 2281
I dont know where the k
was coming from but try to use $
instead
$('.portfolio_classic_icon_content_middle').on('keyup', function(){
var message = $('#gallery_images_comment').val();
console.log(message);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="portfolio_classic_icon_content_middle">
<textarea name="comment" id="gallery_images_comment" form="usrform">This is the text loaded</textarea>
</div>
Upvotes: 0