user755806
user755806

Reputation: 6825

Append a variable values with string using javascript

I have below string.

window.location="./getdata?geo=abc&tab=xyz";

Now i have abc and xyz in var as below:

var geo="abc";
var tab="xyz";

Now how can i append var with above string instead of hard coding them inside a string?

Thanks!

Upvotes: 3

Views: 74

Answers (2)

bgs
bgs

Reputation: 3223

Try below:

var geo="abc";
var tab="xyz";

window.location="./getdata?geo=" + geo + "&tab=" + tab;

'+' symbol used to concotinate the string

Upvotes: 2

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

Try,

window.location="./getdata?geo="+ geo +"&tab=" + tab;

And also please read this to know more about how to do concatenation in Javascript

Upvotes: 5

Related Questions