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
LVL 3
rickyrAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
In your form tag, do this:

<FORM name='buttons' method='post' action='my.cgi'
  onSubmit='this.COMMENTS.value=this.COMMENTS.value.split("\n").join("");return(true);'>

<TEXTAREA name='COMMENTS'></textarea>

</form>
0
 
Michel PlungjanIT ExpertCommented:
Perhaps even
this.COMMENTS.value.split("\n").join("").split("\r").join("");

Michel


0
 
knightEknightCommented:
yes, good catch  :)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
DeatheadCommented:
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
0
 
knightEknightCommented:
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?
0
 
CJ_SCommented:
Or use the replace function

0
 
DeatheadCommented:
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
0
 
knightEknightCommented:
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.
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
knightEknightCommented:
Why am I not surprised?
0
 
rickyrAuthor Commented:
Ta
0
 
waltwebtronCommented:
Yes, why don't we use .replace() ?
0
 
knightEknightCommented:
Because this question was from April of 2000 and IE3 did not support the replace() method.
0
 
Michel PlungjanIT ExpertCommented:
Hehe - FLASHBAAACK
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.