+ Start a Discussion
ShadowlessKickShadowlessKick 

JavaScript button

A javascript button extracts string data from a textarea.  The string has a newline character of "\r\n" inside the html.   When the javascript line is extracted it looks like this -

var TheDrawingNumber = "{!tenrox__c.KI_Drawing_Space_Plan__c}"; 

An error of "Unterminated string constant" is displayed.

How can the value be extracted without the javascript blowing up? 

Is there a way like "{!tenrox__c.KI_Drawing_Space_Plan__c.replace(/(\r\n|\n|\r)/gm, "%2c") }";
SarfarajSarfaraj
Encode it,

var TheDrawingNumber = "{!JSENCODE(tenrox__c.KI_Drawing_Space_Plan__c)}";


ShadowlessKickShadowlessKick
Thank you for responding.  JSENCODE was a good idea but the Javascript still blows up on variable retrieval with a new line inside of the text area.  
SarfarajSarfaraj
This one works for me,
<apex:page standardController="Account">
    <apex:includeScript value="https://code.jquery.com/jquery-2.1.1.min.js"/>
<script type="text/javascript">
    $(document).ready(
        function(){
        var a = "{!JSENCODE(Account.BillingStreet)}";
        alert(a);
        }
    );
</script>

I have following data in correcponding account,
525 S. Lexington Avenue
Burlington
NC
27215
USA

In case your are still unable to make it work, try this,
<apex:page standardController="Account">
    <apex:includeScript value="https://code.jquery.com/jquery-2.1.1.min.js"/>
<script type="text/javascript">
    $(document).ready(
        function(){
        var b = $(document.getElementById("{!$Component.form.BillingStreetInput}")).val();
        alert(b);
        }
    );
</script>
<apex:form id="form">
<apex:inputHidden value="{!Account.BillingStreet}" id="BillingStreetInput"/>
</apex:form>
</apex:page>


ShadowlessKickShadowlessKick
Thank you for tyring to help.  I am not using a visualforce page.  This is a javascript button on a a configurable page layout.