Got the code here:
var i4options = {
TTXT1: [
{val: "01", id: "(01) XT1 Option 1"},
{val: "02", id: "(02) XT1 Option 2"}
],
TTXT2: [
{val: "01", id: "(01) XT2 Option 1"},
{val: "02", id: "(02) XT2 Option 2"}
]
};
function i4check() {
const i1checkval = i1.options[i1.selectedIndex].value;
const i2checkval = i2.options[i2.selectedIndex].value;
const i3checkval = i3.options[i3.selectedIndex].value;
const i4checkoutput1 = "i4options" + i1checkval + i2checkval + i3checkval;
let userSettings = {
'product': i1checkval,
'type': i2checkval,
'source': i3checkval,
};
if (userSettings.product !== '---' && userSettings.type !== '---' && userSettings.source !== '---') {
let newItem = document.createElement('option');
var nofentries = i4options.(i1checkval + i2checkval + i3checkval).length;
var x = 0;
while (x < nofentries){
i4.appendChild(new Option(i4options.(i1checkval + i2checkval + i3checkval)[x].id, i4options.(i1checkval + i2checkval + i3checkval)[x].val));
x += 1;
}
}
}
function generatordropdown(){
var o1 = i1.options[i1.selectedIndex].value;
var o2 = i2.options[i2.selectedIndex].value;
var o3 = i3.options[i3.selectedIndex].value;
var o4 = i4.options[i4.selectedIndex].value;
var output = o1 + o2 + o3 + o4;
document.getElementById("output").value = output;
}
<form action="database/additem.php" method="post">
<h1>product</h1>
<select id="i1" onchange="generatordropdown(); i4check();" name="product">
<option selected="true" disabled="disabled">---</option>
<option value="T">(T) Telephone</option>
</select><br>
<h1>type</h1>
<select id="i2" onchange="generatordropdown(); i4check();" name="type">
<option selected="true" disabled="disabled">---</option>
<option value="T">(T) Model T</option>
</select><br>
<h1>source</h1>
<select id="i3" onchange="generatordropdown(); i4check();" name="source">
<option selected="true" disabled="disabled">---</option>
<option value="XT1">(XT1) XT1</option>
<option value="XT2">(XT2) XT2</option>
</select><br>
<h1>i4</h1>
<select id="i4" onchange="generatordropdown()" name="category">
<option selected="true" disabled="disabled">---</option>
</select><br>
<h1>ID</h1>
<input onClick="this.setSelectionRange(0, this.value.length)" type="text" id="output" name="id" style="width: 50%;" readonly><br>
</form>
Or if you prefer jsfiddle: https://jsfiddle.net/2kd6LdLc/
On line 27 and 30 it says:
(i1checkval + i2checkval + i3checkval)
What I'm trying to do here is have the code check TTXT1 if option i3 is XT1, and check TTXT2 if option i3 is XT2. I could do this with if statements but I want to easily add new objects if I have to, so I dont want to have to add an if statement every time. Any suggestions on how to do this? I'm fine with using eval() if it's the only way but I don't know how I would go about using it.