I have a function that displays comments in DIV box from a database. The DIV also has a form for adding new comments.
The form is got from the PHP script so it is live().
The submit button submits a live click event no probs, but the new comment text is empty.
How can I get textfield contents from an AJAX DIV form?
Here is the code:
$('#submit_comment').live('click', function(e) {
alert('comment submit');
e.preventDefault();
var comment = $('#new_comment').live().val(); // ????
alert(comment); // comment is empty
if (comment != '') {
$('#loading').show();
$('#commentsPanel').hide();
// loading = true
var track = $('#trackID').val();
alert(track);
var data = 'track=' + track + '&isComment=true&comment=' + comment;
alert(data);
$.ajax({
url: 'comment.php',
type: 'GET',
data: data,
cache: false,
success: function (comments_html) {
alert('submit_comment');
$('#commentsPanel').html(comments_html);
$('#commentsPanel').show();
$('#loading').hide();
}
});
}
else {
}
});
Many thanks!
Have u tried?
liveis used to attach a handler to the event for all elements which match the current selector, now and in the future.if you are trying to get the value of the textbox only the above code is enough.