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
You're looking for .val()
:
$("#commentField").val('');
Since textarea
is a input field it has a value
property so you have to use val()
method. Try this
$("#commentField").val('');
In jQuery it's actually $("#commentField").val(" ");
You can remove text from the textarea like this:
$("#commentField").html("");
EDIT: ok, this does not work, but I'd be really interested as to why, and I understand the down-vote. I always thought that the text between the textarea
tags was innerHTML and html()
is supposed to replace just that. Wouldn't it make sense to have textarea like input? or is it just because textareas contain long amounts of text that would look tacky between quotation marks?.
Using regular javascript with innerHTML it works for me in FF6. demo here
1) <textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
2) CKEDITOR.replace('editor1');
3) initiated = true;
to write your text in you text area
1)$("#editor1").val("your input value");
to clean your text area
1) $("#editor1").reset();
tank you for reading this.
来源:https://stackoverflow.com/questions/7109352/jquery-remove-user-input-text-from-textarea