concatenate variable in link - javascript

0

My problem is in the parameter passing in the link, because there on the page that receives, the variables are arriving as value instead of the values.

I believe the problem is really in the concatenation of variables in link building.

Variables are either decimal or integer numbers.

var ins = 123.46;
var newcostumer = 456889; 

<script src="http://teste.testando.com.br/da.js?pagina=home&inst=ins&newcustomer=nc&id=123"async="async"> </script>
    
asked by anonymous 20.12.2017 / 05:03

1 answer

1

You can use document.write to construct the URL by passing variables:

<script>
var ins = 123.46;
var newcostumer = 456889;
document.write('<scr'+'ipt src="http://teste.testando.com.br/da.js?pagina=home&inst='+ins+'&newcustomer='+newcostumer+'&id=123"async="async"> </scr'+'ipt>');
</script>

Note that it was necessary to make two concatenations scr'+'ipt so that JavaScript does not create a script within the other, resulting in an error.

    
20.12.2017 / 05:30