Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append text to '<textarea>'?

I have <textarea> where user can type in his message to the world! Below, there are upload buttons... I would love to add link to uploaded file (don't worry, I have it); right next to the text that he was typing in.

Like, he types in 'Hello, world!', then uploads the file (its done via AJAX), and the link to that file is added in next line to the content of <textarea>. Attention! Is it possible to keep cursor (place where he left to type) in the same place?

All that may be done with jQuery... Any ideas? I know that there are method 'append()', but it won't be for this situation, right?

like image 389
daGrevis Avatar asked Jul 18 '11 14:07

daGrevis


People also ask

How do I add text to textarea?

To add text to a textarea, access the value property on the element and set it to its current value plus the text to be appended, e.g. textarea. value += 'Appended text' . The value property can be used to get and set the content of a textarea element.

Can I add value to textarea?

To add a value into a textarea, you can add to the value property of the input via document. getElementById. Reference this element and change the value: document.


1 Answers

Try

var myTextArea = $('#myTextarea');
myTextArea.val(myTextArea.val() + '\nYour appended stuff');
like image 76
James McCormack Avatar answered Sep 17 '22 16:09

James McCormack