ezryder
05-09-2004, 04:29 PM
hi,
I'm using a php class to make a form with 3 dropdown lists. What is in the second list is dependent upon the value which is in the first list.
whenever the first list is changed the second list should update automatically - however it doesn't.
Can anyone tell me where the code produced by by class is wrong? This is the html output:
<HEAD>
<meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)">
<title>Sample</title>
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var currentreigon = 0 ;
var currentlea = 0 ;
var arrayleaTXT = new Array();
var arrayleaVAL = new Array();
arrayleaTXT[0] = "";
arrayleaVAL[0] = 0;
arrayleaTXT[East] = "Ipswich|Norwich";
arrayleaTXT[North West] = "Bolton|bury";
arrayleaTXT[Reigon] = "LEA";
arrayleaTXT[South] = "London";
arrayleaTXT[West] = "Cornwall|Wales";
arrayleaVAL[East] = "Ipswich|Norwich";
arrayleaVAL[North West] = "Bolton|bury";
arrayleaVAL[Reigon] = "LEA";
arrayleaVAL[South] = "London";
arrayleaVAL[West] = "Cornwall|Wales";
function baaSelectUpdatelea (form) {
currentreigon = form.reigon.options[form.reigon.selectedIndex].value;
while (form.lea.options.length) {
form.lea.options[0] = null;
}
var tmp = new String (arrayleaTXT[currentreigon]);
var arrayText = tmp.split("|");
tmp = new String (arrayleaVAL[currentreigon]);
var arrayVals = tmp.split("|");
var optionlist = form.lea.options;
optionlist[0] = new Option();
optionlist[0].value = 0;
optionlist[0].text = "--LEA--";
if (arrayleaTXT[currentreigon]) {
for (var i=0; i<arrayText.length; i++) {
optionlist[i+1]=new Option();
optionlist[i+1].value = arrayVals[i];
optionlist[i+1].text = arrayText[i];
if (currentlea == arrayVals[i])
optionlist[i+1].selected = true;
}
}
}
// generated by baaSelect.php -->
</SCRIPT>
# this creates the js
</HEAD>
<BODY>
<form method=get>
<SELECT name="reigon" onChange="baaSelectUpdatelea(this.form)" >
<OPTION value="0" > --Area--</option>
<OPTION value="East" > East</option>
<OPTION value="East" > East</option>
<OPTION value="North West" > North West</option>
<OPTION value="North West" > North West</option>
<OPTION value="Reigon" > Reigon</option>
<OPTION value="South" > South</option>
<OPTION value="West" > West</option>
<OPTION value="West" > West</option>
</SELECT>
SELECT reigon, reigon FROM schools ORDER BY reigon reigon<SELECT name="lea" >
<OPTION value="0" > --LEA--</option>
</SELECT>
SELECT lea, lea FROM schools WHERE reigon = '0' ORDER BY lea lea</form>
</BODY>
</HTML>
Thanks
I'm using a php class to make a form with 3 dropdown lists. What is in the second list is dependent upon the value which is in the first list.
whenever the first list is changed the second list should update automatically - however it doesn't.
Can anyone tell me where the code produced by by class is wrong? This is the html output:
<HEAD>
<meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)">
<title>Sample</title>
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var currentreigon = 0 ;
var currentlea = 0 ;
var arrayleaTXT = new Array();
var arrayleaVAL = new Array();
arrayleaTXT[0] = "";
arrayleaVAL[0] = 0;
arrayleaTXT[East] = "Ipswich|Norwich";
arrayleaTXT[North West] = "Bolton|bury";
arrayleaTXT[Reigon] = "LEA";
arrayleaTXT[South] = "London";
arrayleaTXT[West] = "Cornwall|Wales";
arrayleaVAL[East] = "Ipswich|Norwich";
arrayleaVAL[North West] = "Bolton|bury";
arrayleaVAL[Reigon] = "LEA";
arrayleaVAL[South] = "London";
arrayleaVAL[West] = "Cornwall|Wales";
function baaSelectUpdatelea (form) {
currentreigon = form.reigon.options[form.reigon.selectedIndex].value;
while (form.lea.options.length) {
form.lea.options[0] = null;
}
var tmp = new String (arrayleaTXT[currentreigon]);
var arrayText = tmp.split("|");
tmp = new String (arrayleaVAL[currentreigon]);
var arrayVals = tmp.split("|");
var optionlist = form.lea.options;
optionlist[0] = new Option();
optionlist[0].value = 0;
optionlist[0].text = "--LEA--";
if (arrayleaTXT[currentreigon]) {
for (var i=0; i<arrayText.length; i++) {
optionlist[i+1]=new Option();
optionlist[i+1].value = arrayVals[i];
optionlist[i+1].text = arrayText[i];
if (currentlea == arrayVals[i])
optionlist[i+1].selected = true;
}
}
}
// generated by baaSelect.php -->
</SCRIPT>
# this creates the js
</HEAD>
<BODY>
<form method=get>
<SELECT name="reigon" onChange="baaSelectUpdatelea(this.form)" >
<OPTION value="0" > --Area--</option>
<OPTION value="East" > East</option>
<OPTION value="East" > East</option>
<OPTION value="North West" > North West</option>
<OPTION value="North West" > North West</option>
<OPTION value="Reigon" > Reigon</option>
<OPTION value="South" > South</option>
<OPTION value="West" > West</option>
<OPTION value="West" > West</option>
</SELECT>
SELECT reigon, reigon FROM schools ORDER BY reigon reigon<SELECT name="lea" >
<OPTION value="0" > --LEA--</option>
</SELECT>
SELECT lea, lea FROM schools WHERE reigon = '0' ORDER BY lea lea</form>
</BODY>
</HTML>
Thanks