Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:34:35+00:00 2026-05-30T13:34:35+00:00

So I noticed that a piece of Javascript on my VisualForce page was working

  • 0

So I noticed that a piece of Javascript on my VisualForce page was working in some cases, and wasn’t in others. JS was doing some operations on a textArea field from one of the custom objects we have. I realized that JS was breaking whenever that textArea field had a new line or carriage return character in it (\n and \r).

So I ended up using a replaceAll() method in the page controller, and removing all of those characters from that textArea field on page load. By the time it got to JS, it was a legal string.

on the VF PAGE:

<script language="JavaScript">
function someFunction() {
    var leftOver = 220;           

    if('{!shippingAddress.Delivery_Requirements__c}'.length > 0){
        leftOver -= '{!shippingAddress.Delivery_Requirements__c}'.length;
    }                                             
}            
</script>

in the controller:

//a fix for the text area field - '\n' and '\r' breaks JS on the VF page        
shippingAddress.Delivery_Requirements__c = shippingAddress.Delivery_Requirements__c.replaceAll('\r\n', ' ');

Posting this as a heads up for anyone who encounters JS working for some records and not for others.

If you have insight on why it breaks, do tell.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:34:36+00:00Added an answer on May 30, 2026 at 1:34 pm

    It’s breaking because JavaScript doesn’t allow literal line breaks in strings. This would probably fix it while allowing the line breaks:

    public String getDeliveryRequirements() { 
        return shippingAddress.Delivery_Requirements__c.replace('\r\n', '\\r\\n');
    }
    

    Then in the VF page, bind to the getter from above:

    if('{!DeliveryRequirements}'.length > 0){
        leftOver -= '{!DeliveryRequirements}'.length;
    }     
    

    Update:

    manubkk’s answer is better. But I think the correct javascript syntax would be:

    var deliveryRequirements = "{!JSENCODE(shippingAddress.Delivery_Requirements__c)}";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was looking over some of our JavaScript compression and noticed that no strings
I've noticed that some simple scripts in JavaScript that work perfectly on my local
i've just noticed that some javascript i;ve just written appears to be leaking memory,
I noticed that some websites (for example: apple.com or disqus.com) don't send AJAX request
I've got a JSP page with a piece of Javascript validation code which limits
While running through a piece of code for performance tuning, i noticed that the
I have inherited a piece of Javascript that uses the Google Feed API. It
I was working on a piece of code to do some compression, and I
I'm working on a framework and have run into an issue. I noticed that
I noticed that Google maps is providing directions in my local language (hungarian) when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.