-2

I need help to grab information from a textarea. When I click on a link named "Edit", the div beside it containing a note, is transformed from a div to a textarea.

I do this with the following code:

$(".edit").click( function(){
var id = parseInt($(this).attr('id').split('_')[1]); //returns the unique integer
//edit only the div with that integer assigned
$('#edit_note_'+id).replaceWith(function() {
        return $("<textarea name='anteckning' style='width: 550px; height: 350px;'>").text(this.textContent);
    });
    $('.show_edit_button_'+id).show();
});

After I have finished editing the note, I want to upload it to the database. But I don't know how to grab the edited text in the textarea? I've tried .text(), but when I use it, it is declares as undefined.

Anyone who can help me?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user500468
  • 1,183
  • 6
  • 21
  • 36

2 Answers2

0

Try this:

$('input#mybutton').click(function() {
    var text = $('textarea#mytextarea').val();
    //send to server and process response
});

Source: jQuery get textarea text

Community
  • 1
  • 1
Haudegen
  • 498
  • 1
  • 4
  • 17
0

Before replace the content of the div you should get the data before put the textarea and when you have your textarea created, then you can put the data stored before in a variable.

Arleal
  • 66
  • 3