I have that simple problem of drill down through three combination lists. First list is selection of common or latin names, second one is list of trees (with common or latin names) and third list is varieties for the selected tree in the second list.
I want to generate the (array) dataset via PHP which will not be a real problem and then after selection of variety jump to PHP to perform a database query on the basis of the values in the three lists (also no problem).
The point is that I somehow can't get the following JavaScript code to do what it should do (eg. the repop_tree function seems to run only once through the for.next). Can someone please have a look at the code below.
<html>
<head>
<script language="javascript">
<!--
//This data section is generated via PHP
var tree = new Array(3);
tree[0] = new Array(4);
tree[0]['ID'] = 9;
tree[0]['common'] = "First Common tree name";
tree[0]['latin'] = "First Latin tree name";
tree[0]['variety'] = new Array();
tree[0]['variety'][0] = new Array(2);
tree[0]['variety'][0]['ID'] = 2;
tree[0]['variety'][0]['name'] = "First variety name_9";
tree[0]['variety'][1]['ID'] = 5;
tree[0]['variety'][1]['name'] = "Second variety name_9";
tree[0]['variety'][3]['ID'] = 6;
tree[0]['variety'][3]['name'] = "Third variety name_9";
tree[1] = new Array(4);
tree[1]['ID'] = 14;
tree[1]['common'] = "Second Common tree name";
tree[1]['latin'] = "Second Latin tree name";
tree[1]['variety'] = new Array();
tree[1]['variety'][0] = new Array(2);
tree[1]['variety'][0]['ID'] = 7;
tree[1]['variety'][0]['name'] = "First variety name_14";
tree[2] = new Array(4);
tree[2]['ID'] = 18;
tree[2]['common'] = "Third Common tree name";
tree[2]['latin'] = "Third Latin tree name";
tree[2]['variety'] = new Array();
tree[2]['variety'][0] = new Array(2);
tree[2]['variety'][0]['ID'] = 8;
tree[2]['variety'][0]['name'] = "First variety name_18";
//FUNCTIONS
function repop_tree(d,s) {
var language = s.options[s.selectedIndex].value;
var treelist = tree;
for(var idx=0; idx < treelist.length; idx++ ) {
tmp = new Option( treelist[idx][language], treelist[idx]['ID'] );
d.options[idx] = tmp;
}
return true;
}
function repop_variety(d,s) {
var varietielist = tree[0];
for(var idx=0; idx < 4; idx++ ) {
tmp = new Option( varietielist[idx],1 );
d.options[idx] = tmp;
}
return true;
}
// -->
</script>
</head>
<body>
<FORM METHOD=POST ACTION="test3.php">
<select name="language" onChange="repop_tree(this.form.tree,this)">
<option value="common">Common</option>
<option value="latin">Latin</option>
</select>
<select name="tree" onChange="repop_variety(this.form.variety,this)">
<option value="">_________________</option>
</select>
<select name="variety">
<option value="">_________</option>
</select>
<INPUT TYPE="SUBMIT" VALUE="Show">
</form>
</body>
</html>😕