-1

I'm having trouble passing query_enc var value from first <script> tag to second <script> tag src here is my code -

<script>
var query_enc = "";
var query = "%inputParams.query%";
if !( stringStartsWith(query, "%" && stringEndsWith(query, "%")
{  
query_enc = encodeURIComponent(query);
}
buildUrl(query_enc);

</script>


<script src="http://keyword.monfuel.com/sponsored.js?q='+query_enc+'&url=%inputParams.clientSiteUrl%&height=250&sp1=sitefuel&sp2=Latestmotorcyceles&sp3=BB&padding=7"></script>

this is the result

<script src="http://keyword.monfuel.com/sponsored.js?q=**'+query_enc+'**&amp;url=http://latestmotorcycles.com/&amp;height=250&amp;sp1=sitefuel&amp;sp2=Latestmotorcyceles&amp;sp3=BB&amp;padding=7"></script>
ElramV
  • 315
  • 3
  • 14
  • You will need to create the script elemetn dynamically and add it to the document – Arun P Johny Jan 22 '16 at 07:46
  • Your basic syntax is horribly incorrect. `if !( stringStartsWith(query, "%" && stringEndsWith(query, "%")` will throw a `SyntaxError`. – Oka Jan 22 '16 at 07:49

1 Answers1

0

You could use PHP or server-side language, but if you're doomed to JavaScript. You should create the element on the fly (dynamically).

var s = document.createElement( 'script' );
s.setAttribute( 'src', 'http://keyword.monfuel.com/sponsored.js?q='+query_enc+'&url=%inputParams.clientSiteUrl%&height=250&sp1=sitefuel&sp2=Latestmotorcyceles&sp3=BB&padding=7');
document.head.appendChild(s);
Adam Azad
  • 10,675
  • 5
  • 25
  • 63