Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear text area

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> 
like image 311
vinanghinguyen Avatar asked Nov 27 '11 10:11

vinanghinguyen


People also ask

How do you clear a text box in HTML?

To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.

How do I restrict text area?

You can set the size of a text area using the cols and rows attributes. To limit the number of characters entered in a textarea, use the maxlength attribute. The value if the attribute is in number. Specifies that on page load the text area should automatically get focus.

How do I display textarea content in HTML?

Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.


2 Answers

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.

like image 58
Jakub Arnold Avatar answered Oct 02 '22 22:10

Jakub Arnold


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.

like image 34
Karl Wenzel Avatar answered Oct 02 '22 20:10

Karl Wenzel