Tags:
create new tag
view all tags

Question

I have been working with formatted searches for a while now and have come accross a sticky problem. I have several form fields storing this and that about an issue. One of the fields is a text area. The problem occurs when the text area contains line feeds or carriage returns. This didn't show up at first, since the problems is actually only evident when using conditional results with the SpreadSheetPlugin. The carriage returns in the formfield cause the search syntax to show up on the search page.

I checked the support web to see if I was the only fella having this problem, and hopefully to find a solution. I had seen mention of a solution from time to time, but nothing that was shared with others. I recently delegated the task of fixing this little problem to a coworker. He came up with a pretty simple little javascript so I thought I'd share...

I'm also replacing commas and parenthesis for the same reason.

// Replaces carriage returns with <br> to fix formatted search results
function checkText(Form, Field) {
        //Textarea
        var urBrowser = navigator.appName;
   var oldText = document.forms[Form].elements[Field].value;

        if (urBrowser == "Netscape"){
            var ripBRText = oldText.replace(/\n/gi, "<br>"); // Replaces carriage returns with <br>
            var ripComma = ripBRText.replace(/,/gi, "&#44;"); // Replaces commas with ascii code
            var ripOpenParen = ripComma.replace(/\(/gi, "&#40;"); // Replaces Open Parenthesis with ascii
            var ripClosedParen = ripOpenParen.replace(/\)/gi, "&#41;"); // Replaces Closed Parenthesis with ascii
        }else if (urBrowser == "Microsoft Internet Explorer"){
            var ripBRText = oldText.replace(/\r\n/gi, "<br>");
            var ripComma = ripBRText.replace(/,/gi, "&#44;");
            var ripOpenParen = ripComma.replace(/\(/gi, "&#40;");
            var ripClosedParen = ripOpenParen.replace(/\)/gi, "&#41;");            
        } 
        
        // Returns altered text
   document.forms[Form].elements[Field].value = ripClosedParen;

adding the onChange event to call the above code replaces commas parenthesis and carriage returns with ascii codes or <br>. This may not be the most elegant solution ever, but it has fixed our problem. Hopefully it will be helpful for others as well.

Environment

TWiki version: TWikiRelease04x00x04
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Ubuntu Linux
Web server: Apache 2.0.55
Perl version: 5.8.5
Client OS:  
Web Browser:  
Categories: Search

-- MatthewCardozo - 23 Aug 2006

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

Change status to:
Topic revision: r1 - 2006-08-23 - MatthewCardozo
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.