Solved

textarea will be empty

Posted on 2007-04-02
1
447 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
Comment Utility
Just paste this after copyFlag=false; in copySrcTrgt() function:

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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now