beavere38
06-02-2009, 04:12 PM
Hi everyone,
I have been trying to create a form with 3 dropdowns. When you choose from the first called field4 it populates the next called field5
Similarly when you choose from field5 then field6 gets populated.
It all seemed to work fine but then I realised that if I changed the first drop to another choice after having made choices from the other two drops then there was a problem. The second drop changed fine but I then wanted the third drop to become "Choose One" until a choice had again been made from the Second drop. (Hope that makes sense!)
Anyway, I have almost done it, but if I change my first drop now (with the third drop set to a choice) then the third drop appears to change to be completely blank and I have a choice of blank or "Choose one"
Here is my code, I'm no Javascript expert and I have been struggling on this for hours - I am sure one of the experts here can spot in an instant where I have gone wrong. - I have put *** infront of the lines I added which I thought would do the trick for me
Thanks very much in advance
<SCRIPT LANGUAGE = "JAVASCRIPT">
var emptyOption=('Choose One,0')
var arr1=new Array('','Accountancy,31','Banking,30');
var arr6=new Array('','Teaching,29');
var arr29=new Array('','Music teacher,1');
var arr30=new Array('','Bank Clerk,2','Bank Manager,3');
var arr31=new Array('','Accountant,4','Financial Controller,5');
var selArr=new Array();
var selArr2=new Array();
var testIt;
function setOptions(chosen) {
testIt="";
var selbox = document.form1.field5;
*** var selboxx = document.form1.field6;
selbox.options.length = 0;
*** selboxx.options.length = 0;
if (chosen == "0") {
selbox.options[selbox.options.length] = new Option('Choose One',' ');
*** selboxx.options[selbox.options.length] = new Option('Choose One',' ');
}
if (chosen != "0") {
eval('selArr=arr'+(parseInt(chosen)));
selbox.options[selbox.options.length] = new Option('Choose One','0');
*** selboxx.options[selbox.options.length] = new Option('Choose One','0');
for (var i = 1;i < selArr.length;i++){
selArr2=selArr[i].split(",");
testIt +=selArr2[0]+' - '+selArr2[1]+'\n';
selbox.options[selbox.options.length] = new Option(selArr2[0],selArr2[1]);
}
}
}
function setJOptions(chosen) {
testIt="";
var selbox = document.form1.field6;
selbox.options.length = 0;
if (chosen == "0") {
selbox.options[selbox.options.length] = new Option('Choose One',' ');
}
if (chosen != "0") {
eval('selArr=arr'+(parseInt(chosen)));
selbox.options[selbox.options.length] = new Option('Choose One','0');
for (var i = 1;i < selArr.length;i++){
selArr2=selArr[i].split(",");
testIt +=selArr2[0]+' - '+selArr2[1]+'\n';
selbox.options[selbox.options.length] = new Option(selArr2[0],selArr2[1]);
}
}
}
</SCRIPT>
I have been trying to create a form with 3 dropdowns. When you choose from the first called field4 it populates the next called field5
Similarly when you choose from field5 then field6 gets populated.
It all seemed to work fine but then I realised that if I changed the first drop to another choice after having made choices from the other two drops then there was a problem. The second drop changed fine but I then wanted the third drop to become "Choose One" until a choice had again been made from the Second drop. (Hope that makes sense!)
Anyway, I have almost done it, but if I change my first drop now (with the third drop set to a choice) then the third drop appears to change to be completely blank and I have a choice of blank or "Choose one"
Here is my code, I'm no Javascript expert and I have been struggling on this for hours - I am sure one of the experts here can spot in an instant where I have gone wrong. - I have put *** infront of the lines I added which I thought would do the trick for me
Thanks very much in advance
<SCRIPT LANGUAGE = "JAVASCRIPT">
var emptyOption=('Choose One,0')
var arr1=new Array('','Accountancy,31','Banking,30');
var arr6=new Array('','Teaching,29');
var arr29=new Array('','Music teacher,1');
var arr30=new Array('','Bank Clerk,2','Bank Manager,3');
var arr31=new Array('','Accountant,4','Financial Controller,5');
var selArr=new Array();
var selArr2=new Array();
var testIt;
function setOptions(chosen) {
testIt="";
var selbox = document.form1.field5;
*** var selboxx = document.form1.field6;
selbox.options.length = 0;
*** selboxx.options.length = 0;
if (chosen == "0") {
selbox.options[selbox.options.length] = new Option('Choose One',' ');
*** selboxx.options[selbox.options.length] = new Option('Choose One',' ');
}
if (chosen != "0") {
eval('selArr=arr'+(parseInt(chosen)));
selbox.options[selbox.options.length] = new Option('Choose One','0');
*** selboxx.options[selbox.options.length] = new Option('Choose One','0');
for (var i = 1;i < selArr.length;i++){
selArr2=selArr[i].split(",");
testIt +=selArr2[0]+' - '+selArr2[1]+'\n';
selbox.options[selbox.options.length] = new Option(selArr2[0],selArr2[1]);
}
}
}
function setJOptions(chosen) {
testIt="";
var selbox = document.form1.field6;
selbox.options.length = 0;
if (chosen == "0") {
selbox.options[selbox.options.length] = new Option('Choose One',' ');
}
if (chosen != "0") {
eval('selArr=arr'+(parseInt(chosen)));
selbox.options[selbox.options.length] = new Option('Choose One','0');
for (var i = 1;i < selArr.length;i++){
selArr2=selArr[i].split(",");
testIt +=selArr2[0]+' - '+selArr2[1]+'\n';
selbox.options[selbox.options.length] = new Option(selArr2[0],selArr2[1]);
}
}
}
</SCRIPT>