Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] jQuery append text to textarea

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #30579
    marcdefiant
    Participant

    Hey guys, I have a little script here to make links.

    it has two input textareas which will take the link and text inputted and make a shortcode for a user.

    My jQuery is as follows:

    $(function(){
    $('#addLink').click(function(){
    var link = $('#link').val();
    var text = $('#linkText').val();
    $('#edit').append("n" +'[link:' +text +'|' +link +']');
    $('#link').val('http://');
    $('#linkText').val('');
    });
    });

    It works fine…. Up until I edit anything in the textarea manually, then the code doesn’t want to append the text to the textarea. I have a live version on my test site right now. Any help would be appreciated. Thanks.

    #77991
    Chris Coyier
    Keymaster

    is the .append() the problem? Usually textareas are edited by using .val() to change the current value. You could pull in the current value, append, and put back.

    var $edit = $("#edit");
    var curValue = $edit.val();
    var newValue = curValue + "whatever new stuff here";
    $edit.val(newValue);
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.