I am developing a WebApp using HTML, JS and Python and the idea is to have some select box where the user select the first one and based on that I pre-select the others on the backend.
The rule is the following:
- if user select A then Level 3
- if user select B then Level 0
- if user select C then show only Level 4 and Level 5
I started something like this:
const DGSelect = document.getElementById('DG');
const STGSelect = document.getElementById('STG');
STGSelect.value = '';
DGSelect.value = '';
function preselectSTG() {
const selectedDGValue = DGSelect.value;
if (selectedDGValue === 'A') {
STGSelect.value = 'LVL 3';
} else if (selectedDGValue === 'B') {
STGSelect.value = 'LVL 0';
} else if (selectedDGValue === 'C') {
STGSelect.value = 'LVL 4';
} else {
STGSelect.value = '';
DGSelect.value = '';
}
}
<form>
<div class="form-group">
<label for="DG">Decision Group:</label>
<select name="DG" id="DG">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">C</option>
</select>
</div>
<div class="form-group">
<label for="STG">STGCD:</label>
<select name="STG" id="STG">
<option value="LVL 0">Level 0</option>
<option value="LVL 3">Level 3</option>
<option value="LVL 4">Level 4</option>
<option value="LVL 5">Level 5</option>
</select>
</div>
</form>
2
Answers
I don’t know if this helps,
I just placed an event listener to make it interactive with the element.
you write a comment below about what is missing and I will do my best to turn the code to work as required.
First, you need an event listener that calls the function.
Second, the function is missing the third case, hiding levels 4 and 5.