What is incorrect in this function ?

Avatar

Avatar

sc203718

Avatar

sc203718

sc203718

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

Magus069

MVP

Avatar

Magus069

MVP

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

sc203718

Avatar

sc203718

sc203718

30-01-2019

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

Avatar

Avatar

_Bruce_Robertson

MVP

Avatar

_Bruce_Robertson

MVP

_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

Mayank_Gandhi

Avatar

Mayank_Gandhi

Mayank_Gandhi

28-01-2019

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

Avatar

Avatar

Magus069

MVP

Avatar

Magus069

MVP

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

Mayank_Gandhi

Avatar

Mayank_Gandhi

Mayank_Gandhi

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