Link to home
Start Free TrialLog in
Avatar of aman0711
aman0711

asked on

Format textarea text

Hi folks,
         The task I am trying to accomplish is,
 
         I have a textarea on my page and I paste some text from an excel          sheet onto this textarea. The format comes up as:

         abcd
         jhjshds
         eyyeye
         yueye
         ndgdjj
         ieieue
         iweiene
 
         What I am trying to achieve is, onmouseout function, this input          should turn into Comma Seperated Values, like:

         abcd, jhjshds, eyyeye, yueye, ndgdjj, ieieue, iweiene

         How to go about this?
SOLUTION
Avatar of code-colors
code-colors
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aman0711
aman0711

ASKER

Hi frzsombor:

               Your solution isnt working right :(
               I have attached the snapshot. Multiple commas indicate the number of times I did mouseout.

comma.PNG
Hi Code-colors,

        Same sort of result with your script as well :(

 

comma2.PNG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi gamarrojgq:
 
                 Your solution didnt work either. Its not doing anything on mouseout.          
Hi aman0711,

The function use "txtTextArea" as the ID of you textarea control, does your control have this ID?
Hi gamarrojgg,
   
                  Yes I do have that. Below is my complete code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
   <script>

		 function FormatTextArea(){
        
            var sdata;
            var newdata = "";           
            sdata = document.getElementById("txtTextArea").value;
            for(i=0; i<sdata.length; i++){
                if (sdata[i].charCodeAt(0) == "\n".charCodeAt(0))
                {
                    newdata = newdata + ",";
                }           
                else
                {
                    if(sdata[i].charCodeAt(0) != 13){
                        newdata = newdata + sdata[i];
                    }
                }
            }
            document.getElementById("txtTextArea").value = newdata;
        }

  </script>


 </HEAD>

 <BODY>
   
    <textarea rows="10" cols="40" id="txtTextArea" onmouseout="javascript:FormatTextArea();" >

	</textarea>


 </BODY>
</HTML>

Open in new window

errr.PNG
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi hielo,

                 Long time :)
 
                 You are the boss :-) Fixed.

                 Thanks a ton.
hi senthurpandian,

                  Your solutions worked too , just a little problem. Its starting the formatted String with a comma
Hi,

I've tried the code and works fine, i'm sending you a file that works in my environment
HTMLPage2.htm
@hielo
Nice solution. :)
>>  Long time :)
Ditto.

>>Thanks a ton.
Anytime

Regards,
Hielo
@frzsombor:
Thank you. Occasionally I manage to get one right :)
Thanks folks. Sorry for closing this late