SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2011
    Location
    Portland
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    textarea post and set return data back into the textarea

    So currently i need to post the values of the textarea on the keypress of enter. After that i must set the return values in the textarea. I have failed many many times. So i hope someone can help me.

    Code:
    $(document).keypress(function(e) {
      			if (e.keyCode == 13 && !e.shiftKey) {
        		                e.preventDefault();
    				var te = $('textarea').val();
        			        $.post('includes/request.php' , {name: "value" ,value: te} , function(data){$('textarea').text(data);});
      			}
    });
    coming soon sitejuju.com my new development portfolio

  2. #2
    SitePoint Enthusiast OMGCarlos's Avatar
    Join Date
    Apr 2012
    Location
    Boston, MA
    Posts
    91
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You need to use $('textarea').val()

    text() is used to get the innerHTML, stripped of tags, of an element. However, textarea has no innerHTML per se and instead has a "value" property. So that's why you need to use .val(). text() will work until the textarea's value gets changed (either manually or programmatically) which is why it "sometimes" works and sometimes doesn't.

    I know, confusing.


Bookmarks

Posting Permissions

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