I'm trying to get the value of the text area next to the button and it just returns undefined
every time.
script:
$('#comments-container').on('click', '#edit-comment-btn', (e) => {
e.preventDefault();
e.stopImmediatePropagation();
var commentId = $(this).parent().find('textarea:nth-child(2)').val();
var commentText = $(this).parent().find('textarea:nth-child(3)').val();
alert(commentId);
return; //for testing. always returns undefined for some reason
$.get('/openEditComment', {commentId: commentId, commentText: commentText, openCommentEditJs: true}, (data) => {
$(this).parent().replaceWith(data);
})
})
view:
{{#if userOwnsComment}}
<div class="p-2">
<form id="deleteCommentForm" name="deleteCommentForm" method="GET" action="/deleteComment">
<button id="delete-comment-btn" name="delete-comment-btn" class="btn btn-outline-danger">Delete</button>
<textarea readonly="readonly" id="commentId" name="commentId" style="display: none;">{{_id}}</textarea>
</form>
</div>
<div class="p-2">
{{#if openEditComment}}
<form id="submitEditCommentForm" name="submitEditCommentForm" method="GET" action="/submitEditComment">
<textarea class='text-submission' id='editCommentInput' name='editCommentInput' placeholder='Edit Comment' style='width: 100%; max-width: 100%;' rows='1'>{{text}}</textarea>
<button id="submit-edit-comment-btn" name="submit-edit-comment-btn" class="btn btn-danger">Save</button>
<textarea readonly="readonly" id="commentId" name="commentId" style="display: none;">{{_id}}</textarea>
</form>
{{else}}
<form id="editCommentForm" name="editCommentForm" method="GET" action="/openEditComment">
<button id="edit-comment-btn" name="edit-comment-btn" class="btn btn-outline-danger">Edit</button>
<textarea readonly="readonly" id="commentId" name="commentId" style="display: none;">{{_id}}</textarea>
<textarea readonly="readonly" id="commentText" name="commentText" style="display: none;">{{text}}</textarea>
</form>
{{/if}}
</div>
{{/if}}
I have tried getting the value through $(this).next().find('textarea').eq(0);
and still nothing.