Clear text area

JqueryUploadify

Jquery Problem Overview


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>

Jquery Solutions


Solution 1 - Jquery

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 - Jquery

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 - Jquery

This works:

$('#textareaName').val('');

Solution 4 - Jquery

try this

 $("#vinanghinguyen_images_bbocde").attr("value", ""); 

Solution 5 - Jquery

> This method removes not only child (and other descendant) elements, > but also any text within the set of matched elements. This is because, > according to the DOM specification, any string of text within an > element is considered a child node of that element.

$('textarea').empty()

Solution 6 - Jquery

Try this,

$('textarea#textarea_id').val(" ");

Solution 7 - Jquery

I just tried using this code and @psynnott's answer was correct though I needed to know it would work repeatedly, seems to work with jquery 1.7.1 >

I modified the jfiddle to the following http://jsfiddle.net/Rjj9v/109/

$('#mytext').text('');

This is not a new answer @psynnott is correct I am just providing a more concise example that shows the textarea is still working after the clear because if you use .val("") the text area stops working

Solution 8 - Jquery

I believe the problem is simply a spelling error when writing bbcode as bbocde:

$("#vinanghinguyen_images_bbocde").val('')

should be:

$("#vinanghinguyen_images_bbcode").val('')

Solution 9 - Jquery

Rather simpler method would be by using JavaScript method of innerHTML.

document.getElementById("#id_goes_here").innerHTML = "";

Rather simpler and more effective way.

   

Solution 10 - Jquery

Correct answer is: $("#selElement_Id option:selected").removeAttr("selected");

Solution 11 - Jquery

I agree with @Jakub Arnold's answer. The problem should be somewhere else. I could not figure out the problem but found a work around.

Wrap your concerned element with a parent element and cause its html to create a new element with the id you are concerned with. See below

<div id="theParent">
    <div id="vinanghinguyen_images_bbocde"></div>
</div>

'onSelect'    : function(event,ID,fileObj) {
 $("#theParent").html("<div id='vinanghinguyen_images_bbocde'></div>");
 $("#vinanghinguyen_result").hide();
 $(".uploadifyQueue").height(315);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvinanghinguyenView Question on Stackoverflow
Solution 1 - JqueryJakub ArnoldView Answer on Stackoverflow
Solution 2 - JqueryKarl WenzelView Answer on Stackoverflow
Solution 3 - JquerymzonerzView Answer on Stackoverflow
Solution 4 - JqueryconfuciusView Answer on Stackoverflow
Solution 5 - Jqueryuser669677View Answer on Stackoverflow
Solution 6 - JqueryAchu SView Answer on Stackoverflow
Solution 7 - JqueryduindainView Answer on Stackoverflow
Solution 8 - JqueryDaniel NordhView Answer on Stackoverflow
Solution 9 - JqueryAkash KumarView Answer on Stackoverflow
Solution 10 - Jqueryuser1920925View Answer on Stackoverflow
Solution 11 - JqueryNeoView Answer on Stackoverflow