function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GrantMGrantM 

sforce control - hanging while accessing custom fields with carriage return

Hi

I am using a Custom Control to redirect our users to the Edit Contact Page.
I am also passing some account information in the query string.

This has been working fine, Except when trying to access one of our custom fields (an address field) where the user has put carriage returns in the data.

i.e.
      17 Hammer Street
      Hammer house

Now i am using javascript to redirect the user to the contact page. Whenever i try access the field that has carriage returns on it, the javascript does not seem to execute. Trying different accounts without this carriage return worked fine.
I tried replacing the carriage return, but cannot even get that far.

I reduced the script in the sforce control to the following:

<script language="JavaScript">
function showaddress()
{
       alert("{!Account_WCF_Billing_Street}");
}
showaddress();
</script>

Again, this code runs fine for accounts in which this custom field has no carriage returns, yet just doesn't run for fields with carriage returns.

Any way around this, TIA

ScotScot

The problem is that the subsitution of the field into the JavaScript is a straight text substitution, thus the new-line characters cause an end of line for the script, and a syntax error.

There's a trick ... described in detail in another comment ... to put the value of the substitution field into a hidden textarea field on a form, and then reference the hidden field in your javascript. This works because the HTML for the textarea accepts the values with newlines.

I'm not sure of the HTML syntax to make a hidden text area.
The following, roughly, illustrates the idea:

[form name=dummy method=post]
[textarea  name=street id=street]
{!Account_WCF_Billing_Street}
[/textarea][/form]

[script language="JavaScript"]
function showaddress()
{
       alert(document.dummy.street.value);
}
showaddress();
[/script]

The_FoxThe_Fox
Hi

another solution is to create an hidden div
and get the value with document.getelementbyId('ID DU DIV').innerHTML in the javascripts

example
[div id="subjecth" style="position:absolute; visibility:hidden">{!Call_Report_Subject}
[/div>
[script language="JavaScript">
[!--
var CallSubject = "Call Report: " + document.getElementById('subjecth').innerHTML
-->
[/script>
Regards

Message Edited by The_Fox on 06-30-2005 09:52 AM

Message Edited by The_Fox on 06-30-2005 09:52 AM

GrantMGrantM
Thanks guys, that was exactly what i needed.
ScotScot
Nice ... that's much easier.
sf consultant.ax380sf consultant.ax380
I see how this will work in the use case described but what If I want to remove the line breaks from a standard field that the user is entering data in immediately before my sControl is called..

ie.. user is on say case detail.. enters a description with a bunch of line breaks.. hits submit.. my s-control is called...... i guess is there an easy way to reference the id of this field generically in code ie.. document.formname.casedescription or somthing.. ie. how am i to know at development time what the id of this field is actually going to be (right now it says cas15 and i'm assuming the form name is somthing dynamic as well.

On another route,Does the server side SUBSTITUTE function work for removing line breaks?????  It would be much easier for me if it did. I tried a number of iterations but can't get that to work.

<textarea  cols="75" id="cas15" maxlength="32000" name="cas15" onpropertychange="handleTextAreaElementChange('cas15', 32000, 'übrig', 'über Grenze');" rows="6" tabindex="2" type="text" wrap="soft">test

test

test</textarea>

Thank you very much!
ShikibuShikibu
Here's an example of how to create a javascript variable that points at a component, based on its id. See the manual for more details.

<apex:pageBlockSectionItem id="notify_customer_item">
<apex:outputLabel value="Send Customer Notification" for="notify_customer"/>
<apex:inputCheckbox value="{!notifyCustomer}"
id="notify_customer"/>
</apex:pageBlockSectionItem>
<script>var notifyCustomer = document.getElementById("{!$Component.notify_customer_item.notify_customer}");</script>