added default value for selectors
This commit is contained in:
+31
-2
@@ -14,10 +14,17 @@ function fetchOperativesData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to populate the select element with operatives
|
// Function to populate the select element with operatives
|
||||||
|
// Function to populate the operative dropdown
|
||||||
function populateOperatives(operatives) {
|
function populateOperatives(operatives) {
|
||||||
const select = document.getElementById('operative-select');
|
const select = document.getElementById('operative-select');
|
||||||
select.innerHTML = ""; // Clear any existing options
|
select.innerHTML = ""; // Clear any existing options
|
||||||
|
|
||||||
|
// Add the placeholder option
|
||||||
|
const placeholderOption = document.createElement('option');
|
||||||
|
placeholderOption.value = ""; // Empty value for the placeholder
|
||||||
|
placeholderOption.text = "Select an operative";
|
||||||
|
select.appendChild(placeholderOption); // Add the placeholder option
|
||||||
|
|
||||||
operatives.forEach(operative => {
|
operatives.forEach(operative => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = operative.id;
|
option.value = operative.id;
|
||||||
@@ -28,9 +35,16 @@ function populateOperatives(operatives) {
|
|||||||
// Attach event listener to detect when an operative is selected
|
// Attach event listener to detect when an operative is selected
|
||||||
select.addEventListener('change', (event) => {
|
select.addEventListener('change', (event) => {
|
||||||
const selectedOperativeId = event.target.value;
|
const selectedOperativeId = event.target.value;
|
||||||
|
|
||||||
|
// If placeholder is selected, don't proceed
|
||||||
|
if (!selectedOperativeId) {
|
||||||
|
document.getElementById('operative-modifiers').innerHTML = '';
|
||||||
|
return; // Do nothing when the placeholder is selected
|
||||||
|
}
|
||||||
|
|
||||||
selectedOperative = operatives.find(op => op.id === selectedOperativeId);
|
selectedOperative = operatives.find(op => op.id === selectedOperativeId);
|
||||||
if (selectedOperative) {
|
if (selectedOperative) {
|
||||||
updateOperativeBuffs(selectedOperative)
|
updateOperativeBuffs(selectedOperative); // Update operative modifiers on valid selection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -83,10 +97,18 @@ function fetchWeaponsData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to populate the select element with weapons
|
// Function to populate the select element with weapons
|
||||||
|
// Function to populate the weapon dropdown
|
||||||
function populateWeapons() {
|
function populateWeapons() {
|
||||||
const select = document.getElementById('weapon-select');
|
const select = document.getElementById('weapon-select');
|
||||||
select.innerHTML = ""; // Clear any existing options
|
select.innerHTML = ""; // Clear any existing options
|
||||||
|
|
||||||
|
// Add the placeholder option
|
||||||
|
const placeholderOption = document.createElement('option');
|
||||||
|
placeholderOption.value = ""; // Empty value for the placeholder
|
||||||
|
placeholderOption.text = "Select a Weapon";
|
||||||
|
select.appendChild(placeholderOption); // Add the placeholder option
|
||||||
|
|
||||||
|
// Populate with actual weapons
|
||||||
weapons.forEach(weapon => {
|
weapons.forEach(weapon => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = weapon.id;
|
option.value = weapon.id;
|
||||||
@@ -97,9 +119,16 @@ function populateWeapons() {
|
|||||||
// Attach event listener to detect when a weapon is selected
|
// Attach event listener to detect when a weapon is selected
|
||||||
select.addEventListener('change', (event) => {
|
select.addEventListener('change', (event) => {
|
||||||
const selectedWeaponId = parseInt(event.target.value);
|
const selectedWeaponId = parseInt(event.target.value);
|
||||||
|
|
||||||
|
// If placeholder is selected, don't proceed
|
||||||
|
if (!selectedWeaponId) {
|
||||||
|
document.getElementById('weapon-stats').innerHTML = '';
|
||||||
|
return; // Do nothing when the placeholder is selected
|
||||||
|
}
|
||||||
|
|
||||||
selectedWeapon = weapons.find(weapon => weapon.id === selectedWeaponId);
|
selectedWeapon = weapons.find(weapon => weapon.id === selectedWeaponId);
|
||||||
if (selectedWeapon) {
|
if (selectedWeapon) {
|
||||||
updateWeaponStats(selectedWeapon); // Update stats on selection
|
updateWeaponStats(selectedWeapon); // Update stats on valid selection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
var coll = document.getElementsByClassName("collapsible-header");
|
var coll = document.getElementsByClassName("collapsible-header");
|
||||||
for (var i = 0; i < coll.length; i++) {
|
for (var i = 0; i < coll.length; i++) {
|
||||||
coll[i].addEventListener("click", function() {
|
coll[i].addEventListener("click", function () {
|
||||||
this.classList.toggle("active");
|
this.classList.toggle("active");
|
||||||
var content = this.nextElementSibling;
|
var content = this.nextElementSibling;
|
||||||
if (content.style.display === "block") {
|
if (content.style.display === "block") {
|
||||||
@@ -72,13 +72,12 @@
|
|||||||
<main>
|
<main>
|
||||||
<label for="weapon-select">Choose a weapon:</label>
|
<label for="weapon-select">Choose a weapon:</label>
|
||||||
<select id="weapon-select" name="weapons">
|
<select id="weapon-select" name="weapons">
|
||||||
<!-- Weapon options will be populated here dynamically -->
|
<option value="">Select a Weapon</option> <!-- This is the placeholder option -->
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- Operative Select Dropdown -->
|
|
||||||
<label for="operative-select">Pick an Operative</label>
|
<label for="operative-select">Pick an Operative</label>
|
||||||
<select id="operative-select">
|
<select id="operative-select">
|
||||||
<option value="">Select an operative</option>
|
<option value="">Select an operative</option> <!-- This is the placeholder option -->
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user