Link to home
Start Free TrialLog in
Avatar of rickyr
rickyr

asked on

Strip CR from a textarea before sending on to an action.

Hi.....
I have 2 frames..... prod and main.
In main I have 2 frames,  choose  and view
in view I have 2 more frames, show_info and buttons.
in buttons I have a form called buttons and in this form I have a textarea
called COMMENTS.
When I submit the form called buttons it actions another cgi.
What I need to happen is the carriage returns to be stripped away before
the data in the textarea is sent on to my cgi. This must be done at the client in javascript. so don't even say that I can do this at the server.
Please supply full syntax. and info on wher to put the bits.
regards
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America 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
Perhaps even
this.COMMENTS.value.split("\n").join("").split("\r").join("");

Michel


yes, good catch  :)
Avatar of Deathead
Deathead

that is good for codes being executed on the latest browsers, but Some 4.0s and most 3.0s don't handle the .split or .join,
I would suggest bumping through the value character by character and see what it's deci value is then replace all 13s and 10s  ("\n" and "\r")
with a blank space ( to keep the words separate ).


tempString = ""
for(var i=0;i<this.COMMENTS.value.length, i++)
{
  if(this.COMMENTS.value.charcodeAt(i) == 13 || this.COMMENTS.value.charcodeAt(i) == 10)
{
  tempString+=" "
}
else
{
  tempString+=this.COMMENTS.value.charcodeAt(i)
}
}
this.COMMENTS.value = tempString

This will replace the contects of the text area with the stripped value. The best way to do this would be to set this in a function and call it on the submit event of the form
Really.  Which v3+ browsers don't support .split() and .join() ?  I am quite certain that these methods are supported by IE3+ and NN3+, am I wrong?
Or use the replace function

I am pretty sure that IE 3.0 Does not handle the join or split unless I was on a dumped version of it. In which Case I apollogize.
And I have only heard of the 4.0 browsers not taking the meths either.
Again if I am wrong I am sorry.
XDeathead
I know that IE4+ and NS3+ will handle  split() and join(), but I am unable to test IE3.   I would be curious to know though, if you or anyone else can test on IE3, thanks.
IE3 does NOT support split and join! No need to test.

However it also does not support charCodeAt!!!

/* Utility scripts  Michel Plungjan michel(a)plungjan.name */
function mySplit(S,Delim) { // tested on many browsers
   var spl   = new Array();
   if (S.indexOf(Delim) == -1) {
      spl[0] = S;
     return spl;
   }
   var t     = 0;
   var oldp  = 0;
   var p     = 0;
   var dL    = Delim.length;
   while(S.indexOf(Delim,oldp) >= 0) {
      p      = S.indexOf(Delim,oldp);
      spl[t] = S.substring(oldp,p);
      oldp   = p+dL;
      t++;
   }
   if (p < S.length) spl[t] = S.substring(p+dL);
   return spl;
}

function myJoin(theArray,delim) { // not tested
   var str = "";
   if (!delim) delim = "";
   for (var i=0;i<theArray.length;i++) str += delim + "" + theArray[i];
   if (delim.length > 0) str = str.substring(delim.length);
   return str;
}

Michel
Why am I not surprised?
Avatar of rickyr

ASKER

Ta
Yes, why don't we use .replace() ?
Because this question was from April of 2000 and IE3 did not support the replace() method.
Hehe - FLASHBAAACK