You need to sign in to do that
Don't have an account?

Trying to remove illegal characters in JS so i can make a new record
Hi All
I have a JS button on a custom object that copies fields from the record an makes a new record in a different object. One of the fields im trying to copy is a long text area but it often has illegal char's and a lot of weird stuff in it.
So im trying to clean it up an put it into an error box so i can confirm that it works but i still get illegal errors. The code im trying that still errors is:
Can anyone offer up any possiable solutions to this?
Cheers
Dale
I have a JS button on a custom object that copies fields from the record an makes a new record in a different object. One of the fields im trying to copy is a long text area but it often has illegal char's and a lot of weird stuff in it.
ito.incidentDescription__c = "{!ncident__c.incidentDescription__c }";Always results in an Illegal error
So im trying to clean it up an put it into an error box so i can confirm that it works but i still get illegal errors. The code im trying that still errors is:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")} var incidentdesc = "{!Incident__c.incidentDescription__c}" clean = incidentdesc.replace(/[|&;$%@"<>()+,]/g, ""); alert( clean );
Can anyone offer up any possiable solutions to this?
Cheers
Dale
There might be some characters (For instance double quote) in your "incidentDescription__c" field's content that possibly break your Javascript. You need to escape such charcaters first. To do so, you may "JSENCODE" function as shown below.
All Answers
In place of this incidentdesc.replace(/[|&;$%@"<>()+,]/g, "");
Please copy and paste this code incidentdesc.replace(/[|&;$%@<>()+,]/g, "");
Thanks,
Gyanender Singh
07503868174
There might be some characters (For instance double quote) in your "incidentDescription__c" field's content that possibly break your Javascript. You need to escape such charcaters first. To do so, you may "JSENCODE" function as shown below.
Suraj's solution seemed more encompasing. I was able to output the text to a errorbox without any problem with this. However now i cannot insert it into another long text feild in another object.
You will notice in line 53 what i added based on the feedback from Suraj, when this line is here i get a success message but no record is actually written :/. When i remove it i get the expected behaviour.