BPrepper BPrepper - 1 year ago 58
CSS Question

Changing the region in an API url depending on button that is active

I want to change the region in an api url depending on a button the is active.

(Example API: (region).apiurl.net)
If a person selects the button EUW, region would change to EUW, if a person selects Finland, region would change to finland.

How would I start doing this, I'm totally new to javascript and trying to learn, I tried doing this with array's or variables, but nothing worked out for me so far.

Answer Source

Simply use variables, like this:

JS code:

var region;

HTML's buttons:

<button onclick="region='EUW'">Western Europe</button>
<button onclick="region='Finland'">Finland</button>

Finally call the API from JavaSript using your variable:

var apiUrl = region + ".apiurl.net";

I hope you find this useful

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