AnsweredAssumed Answered

Using Score Token in JavaScript issue

Question asked by Takehiro Monday on Jun 17, 2015
Latest reply on Jun 17, 2015 by Sanford Whiteman

Hi all

 

I am creating a dynamic LP using Score Token and JavaScript.

I want to change contents based on the lead Score and some attributes.

But I can not convert Score &#99 format to JavaScript type Number.

 

My Sample

<script type="text/javascript">

<!--

function score2number( score ){

    var number = score;

    for( i = 0 ; i < 10 ; i++ ){

        number=number.replace( "/&#" + 48 + i + ";/g", i );

    }

    return number;

}

 

var x = "{{lead.Test_Score}}";

var n = 0;    // Type Number

document.write("<p>Score=" + x + "</p>");

document.write("<p>len=" + x.length + "</p>");

if( x.length > 0 ){

    n = parseInt(score2number( x ) );

}else{

    // null

    document.write("<p>null</p>");

}

document.write("<p>Number=" + n + "</p>");

-->

</script>

 

Result

Score=65    <==== this lead score is 65 and html is &#54;&#53;

len=10

Number=NaN     <=== Still String type

isNaN=true

 

Please, teach me your solution.

Takehiro

Outcomes