Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

What is incorrect in this function ?

Avatar

Avatar
Validate 1
Level 2
sc203718
Level 2

Likes

3 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 2
sc203718
Level 2

Likes

3 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
View profile
sc203718
Level 2

28-01-2019

I have this error:

TypeError: s.replace is not a function

68:Doc:Init

This is the code that generates the error:

function EL(s)

{

var sir = "";

sir = s.replace(/[&]/g,"&amp;");                            <<<---------------------- this is the error line

sir = sir.replace(/["]/g,"&quot;");

sir = sir.replace(/[“]/g,"&quot;");

sir = sir.replace(/[”]/g,"&quot;");

sir = sir.replace(/[']/g,"&apos;");

  

return sir;

}

I am a newbie in javascript and adobe livecycle designer...what is causing the error ? What should i do

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

28-01-2019

Hi there,

everything seems syntactically correct, so I would say make sure that the parameter 's' is a string...

Hope this will help

Answers (5)

Answers (5)

Avatar

Avatar
Validate 1
Level 2
sc203718
Level 2

Likes

3 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 2
sc203718
Level 2

Likes

3 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
View profile
sc203718
Level 2

30-01-2019

Thanks i solved it, i have to call the .toString() method on the variable

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

30-01-2019

Hi,

I think Magus069 is correct, s will either be null or some other object that doesn't have a replace method, such as a number.

Bruce

Avatar

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct Reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct Reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile
Mayank_Gandhi
Level 10

28-01-2019

I have updated the script that was posted in the question originally, mine is working one

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

28-01-2019

This seem to be working fine for me...

ensure that this.rawValue is in fact returning the value desired...

use app.alert(this.rawValue);

Avatar

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct Reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct Reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile
Mayank_Gandhi
Level 10

28-01-2019

Please try updating script to below:

var sir = "";

sir=this.rawValue;

sir = sir.replace(/[&]/g,"&amp;");                          

sir = sir.replace(/["]/g,"&quot;");

sir = sir.replace(/[“]/g,"&quot;");

sir = sir.replace(/[”]/g,"&quot;");

sir = sir.replace(/[']/g,"&apos;");

Thanks,

Mayank