Solved

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

Posted on 2000-03-30
14
309 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:rickyr
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 total points
ID: 2669140
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2669382
Perhaps even
this.COMMENTS.value.split("\n").join("").split("\r").join("");

Michel


0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2670235
yes, good catch  :)
0
 

Expert Comment

by:Deathead
ID: 2670508
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 2670693
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
 
LVL 22

Expert Comment

by:CJ_S
ID: 2672678
Or use the replace function

0
 

Expert Comment

by:Deathead
ID: 2673947
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 33

Expert Comment

by:knightEknight
ID: 2680227
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2680304
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 2680352
Why am I not surprised?
0
 
LVL 3

Author Comment

by:rickyr
ID: 2686737
Ta
0
 

Expert Comment

by:waltwebtron
ID: 21804752
Yes, why don't we use .replace() ?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 21805397
Because this question was from April of 2000 and IE3 did not support the replace() method.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21809909
Hehe - FLASHBAAACK
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

760 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

21 Experts available now in Live!

Get 1:1 Help Now