Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - remove user input text from textarea

Okay I have a list of devices where i can select which to edit. I have 3 states for the edit. When no devices are selected, when 1 device is selected or when x devices are selected.

The problem i have is when a user type some text in the textarea (commentField) and cancels the edit to edit another device, the text there was typed in the textarea won't disapere. It stays so when i get the new dialog for the new edit, the commentfield has the text from the old commentField (as if it wasn't cleared)

I have tried the following codes to remove the text (both when then cancel button is pressed and when i start a new dialog), but nothing works:

$("#commentField").text(" ");
$("#commentField").value = ' ';

Is there anyone who knows how to remove user-typed text from a textarea using jQuery??

Thanks in advance.

-Thor

like image 749
Thor A. Pedersen Avatar asked Aug 18 '11 14:08

Thor A. Pedersen


3 Answers

You're looking for .val():

$("#commentField").val('');

Example: http://jsfiddle.net/andrewwhitaker/q6eLV/

like image 184
Andrew Whitaker Avatar answered Nov 13 '22 11:11

Andrew Whitaker


Since textarea is a input field it has a value property so you have to use val() method. Try this

$("#commentField").val('');
like image 32
ShankarSangoli Avatar answered Nov 13 '22 12:11

ShankarSangoli


In jQuery it's actually $("#commentField").val(" ");

like image 33
Ali Avatar answered Nov 13 '22 11:11

Ali