Hiii All
I got this script from Mr.Khalid Ali, it wonderful but i 've one problem instead of creating a new list box in a new form, could this be modified to create a static list box in From1 which is dynamicall updated base on the same procesure.
thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Solution for mbevon</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2715.400" name=GENERATOR></HEAD>
<BODY>
<FORM name=form1 action="" method=post><SELECT id=hc style="WIDTH: 100pt"
onchange=processLists(1); name=hc> <OPTION value=http://www.webdeveloper.com/forum/archive/index.php/bb selected>Barbados</OPTION>
<OPTION value=bz>Belize</OPTION> <OPTION value=dm>Dominica</OPTION> <OPTION
value=gd>Grenada</OPTION> <OPTION value=gy>Guyana</OPTION> <OPTION
value=jm>canada</OPTION> <OPTION value=ms>Montserrat</OPTION> <OPTION
value=kn>St. Kitts</OPTION> <OPTION value=lc>St. Lucia</OPTION> <OPTION
value=vc>St. Vincent</OPTION> <OPTION value=tt>Trinidad &
Tobago</OPTION></SELECT> <SELECT id=sc style="WIDTH: 100pt"
onchange=processLists(2); name=sc> <OPTION value=-1 selected>List box
B</OPTION> <OPTION value=1>hs93</OPTION> <OPTION value=2>sitc93</OPTION>
<OPTION value=3>hs96</OPTION> <OPTION value=4>sitc96</OPTION></SELECT> </FORM>
<DIV id=newlist style="POSITION: absolute"></DIV>
<SCRIPT language=JavaScript type=text/JavaScript>
/*
Author Khalid Ali
Date January 2,2003
Create a third List box depending upon the user selected
values from first 2 list boxes
created for Marls.
Special Handling?
A).
Please add values following the pattern below
new Array(1994,1997,1998), separate entries with comma
new Array() last entry must not follow a comma.
you can add as many entries here as you want,just make sure that
they should reconsile with the country code.
for e.g
barbados = bb
and there are 2 entries for it
one array holdes years for hs93/sitc93
and one array holds years for hs96/sitc96
1.new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
2.new Array(1998,1999,2000,2001), //bb -> 1 hs96/sitc96
B).
function createNewListBox(arrA,arrB) in this method
add lines following the pattern
case "ca":
var index = (yrFlag==1)? 4 :5; next value in this sequence will be 6:7
listbox += createListBox(index);
break;
Sample data for sample pre loaded list box values
BB hs93 sitc93 1991,1992,1993,1994,1995,1996,1997,
BB hs96 sitc96 1998,1999,2000,2001
gd hs93 sitc93 1993,1994,1995,1996,1997,1998,1999
gd hs96 sitc96 2000,2001
Ca hs93 sitc93 1994,1997,1998
there's nothing for hs96 sitc96
*/
//create ann array of possible years sequences
var yearArr = new Array(
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001), //bb -> 1 hs96/sitc96
new Array(1993,1994,1995,1996,1997,1998,1999), //gd -> 2 hs93/sitc93
new Array(2000,2001), //bb -> 3 hs96/sitc96
new Array(1994,1997,1998), //bb -> 4 hs93/sitc93
new Array(2000,2001), //bb -> 3 hs96/sitc96
new Array(2000,2001),
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001),
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001),
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001),
new Array() //bb -> 5 hs96/sitc96
); //next index here will be 6 and on
var arrA = new Array();
var arrB = new Array();
var arrC = new Array() //will hold selected values from
//dynamically created list boxes
//values (list box C)
function processLists(flag){
var listA = document.form1.hc;
var listB = document.form1.sc;
var newListStr = "";
var createOK = false;
if(flag==1){
arrA = getSelectedValues(listA);
}else if(flag==2){
arrB = getSelectedValues(listB);
}
if(arrA.length>0 && arrB.length>0){
newListStr +=createNewListBox(arrA,arrB);
createOK = true;
}
if(createOK){
var newlistObject = document.getElementById("newlist");
newlistObject.style.visibility = "visible";
newlistObject.innerHTML =newListStr;
createOK = false;
}
}
function createNewListBox(arrA,arrB){
var listbox="";
var range = new Array();
var yrFlag =Number(getYearFlag(arrB));
for(x=0;x<arrA.length;x++){
var val = arrA[x];
//alert("value ="+val);
switch (val){
case "bb":
var index = (yrFlag==1)? 0 :1;
listbox += createListBox(index);
break;
case "bz":
var index = (yrFlag==1)? 2 :3;
listbox += createListBox(index);
break;
case "dm":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "gd":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "gy":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "jm":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "kn":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "lc":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "vc":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "tt":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
}
}
return listbox;
}
function createListBox(index){
var str="<form name=\"dynamicForm\"><select name=\"tc\" id=\"tc\" onchange=\"processDynaList();\" style=\"width:100pt;\" multiple>";
str +="<option value=http://www.webdeveloper.com/forum/archive/index.php/\"default\">List box C</option>";
for(n=0;n<yearArr[index].length;n++){
var yearVal = parseInt(yearArr[index][n]);
str +="<option value=\""+yearVal+"\">"+yearVal+"</option>";
}
str+="</select></form>";
return str;
}
function getYearFlag(arrB){
var temp = 0;
for(n=0;n<arrB.length;n++){
if(arrB[n]=="1" || arrB[n]=="2"){
temp = 1;
break;
}else if(arrB[n]=="3" || arrB[n]=="4"){
temp = 2;
break;
}
}
return temp;
}
function getSelectedValues(list){
var len = list.length;
var ctr=0;
var values = new Array();
for(x=0;x<len;x++){
if(list[x].selected && list[x].value!="-1"){
values[ctr] = list[x].value;
ctr++;
}
}
return values;
}
function processDynaList(){
var listC = document.dynamicForm.tc;
arrC = getSelectedValues(listC);
var len = arrC.length;
for(z=0;z<len;z++){
alert("You have selected value ["+arrC[z]+"] from third list box.")
//do your appropriate processing here
}
}
</SCRIPT>
</BODY></HTML>
I got this script from Mr.Khalid Ali, it wonderful but i 've one problem instead of creating a new list box in a new form, could this be modified to create a static list box in From1 which is dynamicall updated base on the same procesure.
thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Solution for mbevon</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2715.400" name=GENERATOR></HEAD>
<BODY>
<FORM name=form1 action="" method=post><SELECT id=hc style="WIDTH: 100pt"
onchange=processLists(1); name=hc> <OPTION value=http://www.webdeveloper.com/forum/archive/index.php/bb selected>Barbados</OPTION>
<OPTION value=bz>Belize</OPTION> <OPTION value=dm>Dominica</OPTION> <OPTION
value=gd>Grenada</OPTION> <OPTION value=gy>Guyana</OPTION> <OPTION
value=jm>canada</OPTION> <OPTION value=ms>Montserrat</OPTION> <OPTION
value=kn>St. Kitts</OPTION> <OPTION value=lc>St. Lucia</OPTION> <OPTION
value=vc>St. Vincent</OPTION> <OPTION value=tt>Trinidad &
Tobago</OPTION></SELECT> <SELECT id=sc style="WIDTH: 100pt"
onchange=processLists(2); name=sc> <OPTION value=-1 selected>List box
B</OPTION> <OPTION value=1>hs93</OPTION> <OPTION value=2>sitc93</OPTION>
<OPTION value=3>hs96</OPTION> <OPTION value=4>sitc96</OPTION></SELECT> </FORM>
<DIV id=newlist style="POSITION: absolute"></DIV>
<SCRIPT language=JavaScript type=text/JavaScript>
/*
Author Khalid Ali
Date January 2,2003
Create a third List box depending upon the user selected
values from first 2 list boxes
created for Marls.
Special Handling?
A).
Please add values following the pattern below
new Array(1994,1997,1998), separate entries with comma
new Array() last entry must not follow a comma.
you can add as many entries here as you want,just make sure that
they should reconsile with the country code.
for e.g
barbados = bb
and there are 2 entries for it
one array holdes years for hs93/sitc93
and one array holds years for hs96/sitc96
1.new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
2.new Array(1998,1999,2000,2001), //bb -> 1 hs96/sitc96
B).
function createNewListBox(arrA,arrB) in this method
add lines following the pattern
case "ca":
var index = (yrFlag==1)? 4 :5; next value in this sequence will be 6:7
listbox += createListBox(index);
break;
Sample data for sample pre loaded list box values
BB hs93 sitc93 1991,1992,1993,1994,1995,1996,1997,
BB hs96 sitc96 1998,1999,2000,2001
gd hs93 sitc93 1993,1994,1995,1996,1997,1998,1999
gd hs96 sitc96 2000,2001
Ca hs93 sitc93 1994,1997,1998
there's nothing for hs96 sitc96
*/
//create ann array of possible years sequences
var yearArr = new Array(
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001), //bb -> 1 hs96/sitc96
new Array(1993,1994,1995,1996,1997,1998,1999), //gd -> 2 hs93/sitc93
new Array(2000,2001), //bb -> 3 hs96/sitc96
new Array(1994,1997,1998), //bb -> 4 hs93/sitc93
new Array(2000,2001), //bb -> 3 hs96/sitc96
new Array(2000,2001),
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001),
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001),
new Array(1991,1992,1993,1994,1995,1996,1997), //bb -> 0 hs93/sitc93
new Array(1998,1999,2000,2001),
new Array() //bb -> 5 hs96/sitc96
); //next index here will be 6 and on
var arrA = new Array();
var arrB = new Array();
var arrC = new Array() //will hold selected values from
//dynamically created list boxes
//values (list box C)
function processLists(flag){
var listA = document.form1.hc;
var listB = document.form1.sc;
var newListStr = "";
var createOK = false;
if(flag==1){
arrA = getSelectedValues(listA);
}else if(flag==2){
arrB = getSelectedValues(listB);
}
if(arrA.length>0 && arrB.length>0){
newListStr +=createNewListBox(arrA,arrB);
createOK = true;
}
if(createOK){
var newlistObject = document.getElementById("newlist");
newlistObject.style.visibility = "visible";
newlistObject.innerHTML =newListStr;
createOK = false;
}
}
function createNewListBox(arrA,arrB){
var listbox="";
var range = new Array();
var yrFlag =Number(getYearFlag(arrB));
for(x=0;x<arrA.length;x++){
var val = arrA[x];
//alert("value ="+val);
switch (val){
case "bb":
var index = (yrFlag==1)? 0 :1;
listbox += createListBox(index);
break;
case "bz":
var index = (yrFlag==1)? 2 :3;
listbox += createListBox(index);
break;
case "dm":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "gd":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "gy":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "jm":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "kn":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "lc":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "vc":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
case "tt":
var index = (yrFlag==1)? 4 :5;
listbox += createListBox(index);
break;
}
}
return listbox;
}
function createListBox(index){
var str="<form name=\"dynamicForm\"><select name=\"tc\" id=\"tc\" onchange=\"processDynaList();\" style=\"width:100pt;\" multiple>";
str +="<option value=http://www.webdeveloper.com/forum/archive/index.php/\"default\">List box C</option>";
for(n=0;n<yearArr[index].length;n++){
var yearVal = parseInt(yearArr[index][n]);
str +="<option value=\""+yearVal+"\">"+yearVal+"</option>";
}
str+="</select></form>";
return str;
}
function getYearFlag(arrB){
var temp = 0;
for(n=0;n<arrB.length;n++){
if(arrB[n]=="1" || arrB[n]=="2"){
temp = 1;
break;
}else if(arrB[n]=="3" || arrB[n]=="4"){
temp = 2;
break;
}
}
return temp;
}
function getSelectedValues(list){
var len = list.length;
var ctr=0;
var values = new Array();
for(x=0;x<len;x++){
if(list[x].selected && list[x].value!="-1"){
values[ctr] = list[x].value;
ctr++;
}
}
return values;
}
function processDynaList(){
var listC = document.dynamicForm.tc;
arrC = getSelectedValues(listC);
var len = arrC.length;
for(z=0;z<len;z++){
alert("You have selected value ["+arrC[z]+"] from third list box.")
//do your appropriate processing here
}
}
</SCRIPT>
</BODY></HTML>