concatenate variable into link - javascript

Asked

Viewed 1,636 times

0

My problem is in the parameter passage in the link, because there on the page you receive, the variables are arriving as value instead of the values.

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

Variables shall be 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>
  • It was kind of obscure what you want. What is the goal after all?

  • André, you have to improve the question so we can help. Where do the variables come from? Copy and paste the complete code for understanding. These values are in Hidden input fields or were sent by GET to this page?

  • See if the answer helps you.

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 inside the other, resulting in error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.