For some reason whenever I click enter I get an alertbox with undefined appearing. My script should be getting the “rel” attr and then outputting it to the alertbox. Any ideas as to why this isn’t happening?
My jQuery:
// process addComment()
jQuery(".textbox1").keydown(function(event) {
var keyCode = event.keyCode || event.which;
if (keyCode === 13) {
addComment(this);
}
});
function addComment(e) {
var id = jQuery(e).attr("rel");
alert(id);
}
My Html:
<input placeholder="Write a comment..." id="commentBox-<?php echo $row->idwallPosts; ?>" class="textbox1" style="width: 423px">
in this line
addComment(this);you pass the input object to your function. The object ‘input’ doesn’t have a rel attribute. I assume you want to get the id. Please try: