Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    62
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Jquery append to textarea problem in Firefox

    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:
    PHP Code:
     
    $(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);
                
        });
    }); 

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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:
    Code:
    $("#newtext").val($("#newtext").val() + ch);

  • Users who have thanked Spudhead for this post:

    attasz (07-27-2010)

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    62
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    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:
    Code:
    $("#newtext").val($("#newtext").val() + ch);
    Thx,works fine!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •