Click to See Complete Forum and Search --> : onChange() events
gnanesh
08-08-2003, 08:08 AM
I have two <Select></Select> tags , which are dynamically populated from the Database , this is an J2EE application, based on some value in One Select group i need to display the corresponding items in the Second Select , If any one could let me know about the approach that would be really great , as i need to pass the value of the first one to display corresponding list in the second
thanks
KK
Khalid Ali
08-08-2003, 08:34 AM
create 2 javascript array objects with your j2ee app.
Once page is loaded create one listbox.
Have js in the head section that on selection from the first populates the second listbox using the second array..
The link below will point you in right direction for populating second listbox depending upon the selection from the first one.
http://68.145.35.86/skills/javascripts/MultipleListBoxResult3rdListBox.html
gnanesh
08-08-2003, 09:27 AM
thanks , below is what i took it from your source
// JavaScript Documentvar arrA = new Array();
var arrB = new Array();
var arrC = new Array()
function processLists(flag){
var listA = document.StarsRuleForm.scoreType;
var newListStr = "";
var createOK = false;
if(flag==1){
arrA = getSelectedValues(listA);
if(arrA.length>0){
newListStr +=createNewListBox(arrA);
createOK = true;
}
if(createOK){
var newlistObject = document.getElementById("newlist");
var display = "visible";
newlistObject.style.visibility = display;
newlistObject.innerHTML =newListStr;
}
createOK = false;
}
}
function createNewListBox(arrA){
var listbox="";
var range = new Array();
for(x=0;x<arrA.length;x++){
var val = arrA[x];
//alert("value ="+val);
switch (val){
case "673":
listbox += createListBox(index);
break;
case "674":
listbox += createListBox(index);
break;
case "773":
var index = (yrFlag==1)? 4 :5;
if(yearArr[index].length<=0){
alert("Canada does not have any records");
}
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=\"default\">List box C</option>";
str+="</select></form>";
return str;
}
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 selectOne(){
var listA = document.form1.hc;
listA[listA.length-1].selected = true;
}
Inside createNewListBox(arrA) with the switch values i will be calling createListBox by passing index , so in my situation what should i pass as i don't have 2nd Select box ?
Yours code is really good
If you could let me know that would be really great,
Thanks & Regards
GG
Khalid Ali
08-08-2003, 11:42 AM
you'd consider the second box s your first one and then from there create the second( in ur case).
However I think the link I gave you was a bit complex for the situation you mentioned.
Here this link does exactly what you are looking for.
http://68.145.35.86/skills/javascripts/DropDownSelectCountryShowCities.html