Here's the sitRep:
I've got a 2 drop down menus with several selections each, and the selections ("option:selected" in js) are meant to be query parameters that are connected to an API fetch in my javascript file.
I need to set the value="" within the option on the HTML file to reflect its designation/location in the API, and I've had no luck in discovering the proper syntax.
For clarity, here's a snippet of the html in question:
<select class="form-select form-select-lg mb-3 btn btn-secondary btn-lg" id="platform-drop" aria-label=".form-select-lg example">
<option selected>Platforms:</option>
<option class="dropdown-item" value="playstation-5">Playstation 5</option>
<option class="dropdown-item" value="playstation-4">Playstation 4</option>
<option class="dropdown-item" value="xbox-series">XBOX Series X/S</option>
So, everywhere within that reads <value="xbox-series"> or any other platform needs to instead read something akin to
<option class="dropdown-item" value="apiSource.platforms.id:187">XBOX Series X/S</option>
as the api identifies the XBOX SERIES X/S, in this case, as ->Platform->"id": 187. And that's where I get lost in the woods.
An "under-construction" jS for reference and for anyone wondering why I don't just innerHTML or textContent to a div and be done with it:
var platformBtn = $('#platform-drop');
var genreBtn = $('#genre-drop');
var submitBtn = $('#submit-btn');
submitBtn.on('click', function(event){
event.preventDefault();
var platformSelection = $("#platform-drop option:selected").val();
console.log(platformSelection)
var genreSelection = $('#genre-drop option:selected').val();
console.log(genreSelection)
var gamesUrl = "https://api.rawg.io/api/games?genres="+genreSelection+"&platforms="+platformSelection+"&key=0da6d52b21ec4d8fac88f4f4ceafe806";
fetch(gamesUrl)
.then(function (response) {
if (response.ok) {
return response.json();
}
})
.then(function (data) {
console.log(data.results);
})
})
Any insight would be greatly appreciated.
-LujanSolo