Clear text area
Solution 1
When you do $("#vinanghinguyen_images_bbocde").val('');
, it removes all the content of the textarea, so if that's not what is happening, the problem is probably somewhere else.
It might help if you post a little bit larger portion of your code, since the example you provided works.
Solution 2
Use $('textarea').val('')
.
The problem with using
$('textarea').text('')
, or
$('textarea').html('')
for that matter is that it will only erase what was in the original DOM sent by the server. If a user clears it and then enters new input, the clear button will no longer work. Using .val('')
handles the user input case properly.
Solution 3
This works:
$('#textareaName').val('');
Solution 4
try this
$("#vinanghinguyen_images_bbocde").attr("value", "");
Solution 5
Try this,
$('textarea#textarea_id').val(" ");
vinanghinguyen
Updated on July 08, 2022Comments
-
vinanghinguyen almost 2 years
In Onselect event I have script:
$("#vinanghinguyen_images_bbocde").val(''); $("#vinanghinguyen_images_bbocde").val(vinanghinguyen_final_bbcode);
I want clear text area id="vinanghinguyen_images_bbocde" before add value to it. but textarea add add add add and value and not clear. I want clear it before add value
I use uploadify here is my function
<script type = "text/javascript" > $(document).ready(function() { vinanghinguyen_bbcode = ''; vinanghinguyen_final_bbcode = ''; vinanghinguyen_link = ''; vinanghinguyen_final_derect_link = ''; response = ''; $('#file_upload').uploadify({ 'uploader' : '{SITE_FULL_URL}/uploadify/uploadify.swf', 'script' : '{SITE_FULL_URL}/uploadify/uploadify.php', 'cancelImg' : '{SITE_FULL_URL}/uploadify/cancel.png', 'folder' : 'data/picture_upload/2011', 'auto' : false, 'multi' : true, 'buttonText': '', 'onComplete': function(event, ID, fileObj, response, data) { vinanghinguyen_bbcode = '[IMG]' + 'http://cnttvnn.com' + response + '[/IMG]' + '\n'; vinanghinguyen_final_bbcode = vinanghinguyen_final_bbcode + vinanghinguyen_bbcode; vinanghinguyen_derect_link = 'http://cnttvnn.com' + response + '\n'; vinanghinguyen_final_derect_link = vinanghinguyen_final_derect_link + vinanghinguyen_derect_link; $("#vinanghinguyen_images_bbocde").val('').val(vinanghinguyen_final_bbcode); //$("#vinanghinguyen_images_derect_link").val(vinanghinguyen_final_derect_link); $("#vinanghinguyen_result").show(); $(".uploadifyQueue").height(5); }, 'onSelect': function(event, ID, fileObj) { $("#vinanghinguyen_images_bbocde").val(''); $("#vinanghinguyen_result").hide(); $(".uploadifyQueue").height(315); }, }); }); </script>
-
Cary Bondoc about 9 yearsMaybe you can explain it? Don't just answer, learn to explain everything.
-
Kristen Hammack about 7 yearsTechnically, this clears the textarea and adds a space back into it.
-
duindain about 7 yearsThanks for negging my answer even though its the only one with a working fiddle and it is indeed still correct. Perhaps you should try going to the fiddle and swapping text to val and watch it break after the first change before incorrectly negging answers
-
Kristen Hammack about 7 yearsI didn't neg it. I don't know who did. I was just giving an explanation as to why someone might have.
-
duindain about 7 yearsFair enough, did you try the fiddle yet? since it does break my answer is still correct
-
Kristen Hammack about 7 yearsThat's interesting. Using .val('') seems to break your fiddle, but it doesn't make the text area "stop working". If you type in the text area, it works, and you can get the value from it for a form. Apparently you just can't append to it.
-
SystemFailure almost 6 yearsActually it's
document.getElementById("id_goes_here").innerHTML = "";
# is a jQuery selector. But good job on posting the native JS version.