Author: Ordinary Bits [Yifan]
<HTML>
<HEAD>
<META NAME="AUTHOUR" Content="DANNY KANG">
<META NAME="CreateDate" Content="2004-10-28">
<META NAME="Keywords" Content="DANNY KANG,DannyKang,DK,[DK],pizz">
<META http-equiv=content-type content="text/html; charset=gb2312">
<SCRIPT language=javascript>
//'+--------------------------------------------------
//'+ FileName:
//'+ Created : 2004-10-28 .by pizz [DK]
//'+ Modified: 2004-10-28 .by pizz [DK]
//'+ FuncDesc: Use ASP and JAVASCRIPT to realize the associated display of multiple check box data
//'+ www.downcodes.com
//'+---------------------------------------------
/ /Contents of the first checkbox
var DK_Array1 = new Array();
/*The following parts can be dynamically generated using ASP*/
DK_Array1[DK_Array1.length]=new Array('1','Category 1'); //Category ID, category name
DK_Array1[DK_Array1.length]=new Array('2','Category 2');
DK_Array1[DK_Array1.length]=new Array('3','Category 3');
DK_Array1[DK_Array1.length]=new Array('4','Category 4');
DK_Array1[DK_Array1.length]=new Array('5','Category 5');
DK_Array1[DK_Array1.length]=new Array('6','Category 6');
DK_Array1[DK_Array1.length]=new Array('7','Category 7');
DK_Array1[DK_Array1.length]=new Array('8','Category 8');
///////////////////////////////////////////////////// /////
//Contents of the third check box
var DK_Array3 = new Array();
/*The following parts can be dynamically generated using ASP*/
DK_Array3[DK_Array3.length]=new Array('1','1','Subclass 1.1'); //Category ID, subclass ID, subclass name
DK_Array3[DK_Array3.length]=new Array('1','2','Small class 1.2');
DK_Array3[DK_Array3.length]=new Array('1','3','Small class 1.3');
DK_Array3[DK_Array3.length]=new Array('2','4','Small class 2.4');
DK_Array3[DK_Array3.length]=new Array('2','5','Small class 2.5');
DK_Array3[DK_Array3.length]=new Array('2','6','Small class 2.6');
DK_Array3[DK_Array3.length]=new Array('2','7','Small class 2.7');
DK_Array3[DK_Array3.length]=new Array('3','8','Small class 3.8');
DK_Array3[DK_Array3.length]=new Array('4','9','Small class 4.9');
DK_Array3[DK_Array3.length]=new Array('4','10','Small class 4.10');
DK_Array3[DK_Array3.length]=new Array('4','11','Small class 4.11');
DK_Array3[DK_Array3.length]=new Array('4','12','Small class 4.12');
DK_Array3[DK_Array3.length]=new Array('5','13','Small class 5.13');
DK_Array3[DK_Array3.length]=new Array('5','14','Small class 5.14');
DK_Array3[DK_Array3.length]=new Array('6','15','Small class 6.15');
DK_Array3[DK_Array3.length]=new Array('6','16','Small class 6.16');
DK_Array3[DK_Array3.length]=new Array('6','17','Small class 6.17');
DK_Array3[DK_Array3.length]=new Array('6','18','Small class 6.18');
DK_Array3[DK_Array3.length]=new Array('6','19','Small class 6.19');
DK_Array3[DK_Array3.length]=new Array('7','20','Small class 7.20');
DK_Array3[DK_Array3.length]=new Array('8','21','Small class 8.21');
DK_Array3[DK_Array3.length]=new Array('8','22','Small class 8.22');
///////////////////////////////////////////////////// /////
function DK_AddOnTo(obj,val,txt){ //Add an item
if(DK_CheckExists(obj,val,txt)) {
alert('Option already exists: ['+obj.id+']'+'n Value: '+ val+'n Text: '+txt);
return;
}
var opt=new Option();
opt.value=val;
opt.text=txt;
obj.options.add(opt,0);
}
function DK_InitListObject(obj,array){//Initialization list
if(array.length){
for(var i=0;i<array.length;i++){
DK_AddOnTo(obj,array[i][0],array[i][1]);
}
}
else {
alert('no data');
}
}
function DK_AddTo(src,obj){//Add options to the specified list
for(var i=0;i<src.length;i++){
if(src.options[i].selected){
DK_AddOnTo(obj,src.options[i].value,src.options[i].text);
}
}
}
function DK_SelectAll(obj){ //Select all options
for(var i=0;i<obj.length;i++){
obj.options[i].selected = true;
}
}
function DK_ClearAll(obj){//Delete all options
if(obj.length-1>=0){
for(var i=obj.length-1;i>=0;i--){
obj.remove(i);
}
}
}
function DK_RemoveOne(obj){//Delete the selected item
for(var i=obj.length-1;i>=0;i--){
if(obj.options[i].selected){
obj.remove(i);
}
}
}
function DK_CheckExists(obj,val,txt){//Check whether the item already exists
if(obj.length<0) return false;
for(var i=0;i<obj.length;i++){
if(obj.options[i].value==val && obj.options[i].text==txt) {
return true;
}
}
return false;
}
function DK_ListTo(src,obj,array){//Show subclasses
if(array.length){
var j=0;
for(var i=0;i<src.length;i++){
if(src.options[i].selected){
j+=DK_AddSpecList(src.options[i].value,array,obj);
}
}
alert('A total of '+j+' subcategories were found.');
}
else {
alert('no data');
}
}
function DK_AddSpecList(classid,array,obj){//Search for subclasses
var j=0;
for(var i=0;i<array.length;i++){
if(array[i][0]==classid){
DK_AddOnTo(obj,array[i][1],array[i][2]);
j++;
}
}
return j;
}
</SCRIPT>
<STYLE type=text/css></STYLE>
<TITLE></TITLE>
</HEAD>
<BODY>
<table>
<tr><td colspan=4><input type=button value='Initialization check box one' onclick='DK_InitListObject(select1,DK_Array1)'><br><br>
<tr><td>Check box one: <td><select multiple id=select1 size=8></select>
<td><input type=button value='Add' onclick='DK_AddTo(select1,select2)'> ==>
<td>Check box two:<br><== <input type=button value='Delete' onclick='DK_RemoveOne(select2)'>
<input type=button value='Delete All' onclick='DK_ClearAll(select2)'>
<td><select multiple id=select2 size=8></select>
<td><input type=button value='List related' onclick='DK_ListTo(select2,select3,DK_Array3)'> ==>
<td>Check box three:<br><== <input type=button value='Delete' onclick='DK_RemoveOne(select3)'>
<input type=button value='Delete All' onclick='DK_ClearAll(select3)'>
<td><select multiple id=select3 size=8></select><br>
</table>
</BODY>
</HTML>