?
Solved

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

Posted on 2000-03-30
14
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

771 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