?
Solved

textarea will be empty

Posted on 2007-04-02
1
Medium Priority
?
455 Views
Last Modified: 2012-06-21
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
Thanks.

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

                              src=src.val1.split(",");
                              var trgt=document.getElementById('target');
                              var idx=0;
                              for(var i=0;i<src.length;i++){
                                    idx=trgt.options.length;
                                    var strOpt=trim(src[i]);
                                    if(strOpt.length>0){
                                          trgt.options[idx]=new Option(src[i]);
                                          trgt.size=i+1;
                                    }
                              }
                              copyFlag=false;
                        }

                        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
                                          src.value=src.value.replace("%0D%0A",replaceWith)
                                    }else if(src.value.indexOf("%0A") > -1){
                                          //Unix encodes returns as \n hex
                                          src.value=src.value.replace("%0A",replaceWith)
                                    }else if(src.value.indexOf("%0D") > -1){
                                          //Macintosh encodes returns as \r hex
                                          src.value=src.value.replace("%0D",replaceWith)
                                    }

                              }
                              strObj.val1=src.value;
                              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=src.value.replace(",",'\n')
                                    }

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

                  </script>
            </head>
<body>
<form name="customer">
      <textarea cols="20" rows="8" id="source"></textarea>
      <select id="target" multiple size="1" style="width:150px;">
      </select><br>
      <input type="button" value="Copy" onClick="copySrcTrgt()">
</form>
</body>
</html
0
Comment
Question by:mustish1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
Yury Merezhkov earned 2000 total points
ID: 18839058
Just paste this after copyFlag=false; in copySrcTrgt() function:

document.getElementById("source").value="";
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question