Solved

textarea will be empty

Posted on 2007-04-02
1
449 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web forms being filled out by bots 4 36
How to convert from xls to xlsx using java 7 41
Javascript/JQuery - HtmlEncode (?) Ajax Result 1 39
Else condition 9 19
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

803 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