textarea will be empty

Hi: This process copy data from a textarea in a listbox. Is it possible after i copied data from the textarea the whole textarea will be empty

            <title>Script Demo Gops</title>
                  <script type="text/javascript">
                        var copyFlag=true;
                        function copySrcTrgt(){
                              if(!copyFlag) return false;
                              var src=escapeVal(document.getElementById("source"),',');

                              var trgt=document.getElementById('target');
                              var idx=0;
                              for(var i=0;i<src.length;i++){
                                    var strOpt=trim(src[i]);
                                          trgt.options[idx]=new Option(src[i]);

                        function trim(str) {
                              return str.replace(/^\s+|\s+$/g, "");

                        function escapeVal(src,replaceWith){
                              var strObj=new Object();
                              //src is reference to that object, replaceWith is string that will replace the encoded return
                              src.value = escape(src.value) //encode src string's carriage returns

                              for(var i=0; i<src.value.length; i++){
                                    //loop through string, replacing carriage return encoding with HTML break tag

                                    if(src.value.indexOf("%0D%0A") > -1){
                                          //Windows encodes returns as \r\n hex
                                    }else if(src.value.indexOf("%0A") > -1){
                                          //Unix encodes returns as \n hex
                                    }else if(src.value.indexOf("%0D") > -1){
                                          //Macintosh encodes returns as \r hex

                              for(var i=0; i<src.value.length; i++){
                                    //loop through string, replacing carriage return encoding with HTML break tag

                                    if(src.value.indexOf(",") > -1){

                              src.value=unescape(src.value) //unescape all other encoded characters
                              return strObj;

<form name="customer">
      <textarea cols="20" rows="8" id="source"></textarea>
      <select id="target" multiple size="1" style="width:150px;">
      <input type="button" value="Copy" onClick="copySrcTrgt()">
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yury MerezhkovDevelopment Team LeadCommented:
Just paste this after copyFlag=false; in copySrcTrgt() function:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.