user1447679 user1447679 -4 years ago 201
Javascript Question

How to insert javascript variables into a URL

var a = 1;
var b = 2;
var mylink = "' + a + '&sublist=' + b + '";

This doesn't work. Is there a simple way to insert these other variables into the url query?

Answer Source

By using the right quotes:

var a = 1;
var b = 2;
var mylink = "" + a + "&sublist=" + b;

If you start a string with doublequotes, it can be ended with doublequotes and can contain singlequotes, same goes for the other way around.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download