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
Solved

textarea will be empty

Posted on 2007-04-02
1
450 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
1 Comment
 
LVL 7

Accepted Solution

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

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mobile page Scrolling down when refreshing 4 61
How to display div value on input field value in php 11 51
Html Table looping 4 25
Javascript 2 17
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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

791 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