php - Jquery/Javascript: adding pictures and text dynamically -


forgive me if simple question, kinda novice jquery/javascript. know how can add image , comment @ same time 1 press on enter key. mean is: user types in comment in textarea, hits enter , his/her comment appears in div username. want profile picture corresponding user appears, option rate or favourite comment. have got far following:

$(document).ready(function() {     $('.comment').keyup(function(e) {         if (e.keycode == 13){             var post_id = $(this).attr('post_id');             var comment = $(this).val();             $(this).val('');             $.post('../php_includes/comment.php', {post_id: post_id, comment: comment});             $(this).parent().children('.comments').append("<div class='view'><?php echo $_username;?> remarks: " + comment + "</div>");              }     }); }); 

this works. in div "view" appears: username remarks: comment. however, when this:

$(document).ready(function() {     $('.comment').keyup(function(e) {         if (e.keycode == 13){         var post_id = $(this).attr('post_id');         var comment = $(this).val();         $(this).val('');             $.post('../php_includes/comment.php', {post_id: post_id, comment: comment});         $(this).parent().children('.comments').append("<div class='view'><?php echo $vis_pic;?><?php echo $_username;?> remarks: " + comment + "</div>");                }     }); }); 

($vis_pic containing path userpic) nothing happens - not clear textarea. tried append, prepend, declare html in variable - not want eat it. also, when add php variable display rate , favourite options after adding comment, nothing. driving me nuts scavenged on inet couple of days , nothing seems work. again, sorry if simple question. thank in advance efforts.

instead of showing php code should show result of evaluating it. think problem $vis_pic contains double quotes should escape:

<?php echo str_replace('"', '\"', $vis_pic); ?> 

maybe use addslashes

edit:

you $vis_pic contains

$vis_pic ="<img class=\"commentpic\" src=\"../user/$_userv/mini_profilepic.jpg\">"; 

the problem escaped quotes php, when use echo $vis_pic, php doesn't print \, code becomes:

.append("<div class='view'><img class="commentpic" src="../user/[userv]/mini_profilepic.jpg"> remarks: " + comment + "</div>"); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -