...

View Full Version : Jquery append to textarea problem in Firefox



attasz
07-24-2010, 10:56 AM
I'm working on a shoutbox,my idea is that when somebody click on a smiley i append the appropriate characters to the existing text.Strangely,it works in IE but not in FF.The code is:



$(document).ready(function(){
$("#mybutton").click(function(){
var newText = $("#newtext").val();

$.ajax({
type:"POST",
url:"sendit.php",
cahe:false,
data:"text=" + newText,
success: function(html) {
if(html != "--empty--")
$("#display").append(html);
}
});
});

//this is the relevant part
$("#smileys img").click(function(){
var ch = $(this).attr("alt");
$("#newtext").append(ch);

});
});

Spudhead
07-27-2010, 10:23 AM
I'm guessing it's because append() adds the content as a child of the target element, which, although it sounds right, isn't what you want to do. You want to concatenate your new text onto the value attribute of the input element:

$("#newtext").val($("#newtext").val() + ch);

attasz
07-27-2010, 11:47 AM
I'm guessing it's because append() adds the content as a child of the target element, which, although it sounds right, isn't what you want to do. You want to concatenate your new text onto the value attribute of the input element:

$("#newtext").val($("#newtext").val() + ch);
Thx,works fine!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum