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>
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('');