i want to update the url with different value depend with button you click to use after outside in the fetch primary objectif is to have variable who are update when click that i can use inside the url who change when click on button and the url i can implement after in other function with the value update
var elementId = "";
var url = ""; // Variable globale pour stocker l'URL
function updateElementId(element) {
elementId = element.value;
test();
return elementId;
}
function test() {
url = `https://v3.football.api-sports.io/standings?league=${elementId}&season=2023`;
return url;
}
console.log(url);
console.log(test());
console.log(test());
<div>
<button id="button1" value="5" onclick="updateElementId(this)">
Bouton 1
</button>
<button id="button2" value="45" onclick="updateElementId(this)">
Bouton 2
</button>
<button id="button3" value="3" onclick="updateElementId(this)">
Bouton 3
</button>
<button id="button4" value="75" onclick="updateElementId(this)">
Bouton 4
</button>
<button id="button5" value="42" onclick="updateElementId(this)">
Bouton 5
</button>
</div>
i want to update the url when click on the button and change the value in var inside the url to use in the fetch after
2
Answers
its working well
You can certainly maintain a URL in-memory and alter its query parameters by pressing buttons.
I’d recommend using event delegation to keep the event listeners clean
Then you can use
url
in yourfetch()
calls, triggered however you want