Need help on that code please

Hi Guys,
I have this JS code and it is really working just fine … tit gives me all record based on what is selected on projectname down…

what i need to add is another dropdown to be able to filter by unique “BU”
just fyi how arrays are build here :
if we take
projectid[0] = 112
projectname[0] = MyProjectname

ID[0]= 102
BU[0]= Department 1
DESCRIPTION[0]= this is for department 1
NUM_T[0]= 5
MTH[0]= Oct-2011
NUM_F[0]= 2
NUM_M[0]= 3

for the same project i can have many department

projectid[0] = 112
projectname[0] = MyProjectname

ID[0]= 103
BU[0]= Department 2
DESCRIPTION[0]= this is for department 2
NUM_T[0]= 6
MTH[0]= Nov-2011
NUM_F[0]= 3
NUM_M[0]= 5

and so on

So i want to get the first DDL showing all distinct project …which is done so far

  • I am looking to add a 2nd DDL that includes all distinct BU “departments”
    under same project …

any ine can help on how to get that ?

thanks

below is my code :



<SCRIPT LANGUAGE="JavaScript">



var uniqueProjectIds = [], opt, temp = [];


for(var i = 0; i < PROJECTID.length; i++) 
{

if(uniqueProjectIds[PROJECTID[i]] == null) 
{
uniqueProjectIds[PROJECTID[i]] = [];
opt = document.createElement('option');
opt.text = PROJECTNAME[i]; 
opt.value = PROJECTID[i];


document.forms[0].cmbProjects.add(opt,undefined);
}
temp = uniqueProjectIds[PROJECTID[i]];
temp.push(i);
uniqueProjectIds[PROJECTID[i]] = temp;


}


function showDetails(val) 

{
var tbl = document.getElementById('tblDetails');
while(tbl.rows.length != 1) {
tbl.tBodies[0].deleteRow(tbl.rows.length-1);
}
if(val != '-1') {
var dtls = uniqueProjectIds[val];
for(var i = 0; i < dtls.length; i++) {
var row = tbl.tBodies[0].insertRow(tbl.rows.length);




row.insertCell(0).innerHTML = ID[dtls[i]]
row.insertCell(1).innerHTML = BU[dtls[i]];
row.insertCell(2).innerHTML = DESCRIPTION[dtls[i]];

row.insertCell(3).innerHTML = NUM_T[dtls[i]];
row.insertCell(4).innerHTML = MTH[dtls[i]];
row.insertCell(5).innerHTML = NUM_F[dtls[i]];
row.insertCell(6).innerHTML = NUM_M[dtls[i]];

}
```javascript

}
}

That sounds quite straight forward. All it would take is to loop through each of your projects collating the Distinct BU values, so you can sort them, and then update the second drop down (with show all as the first entry) with their names.

When one is chosen, the onchange event of that drop down is from where you would use the selected BU to update a selected view, if you have one there.

Hi Paul ,

still not working . Can you help please … i tried the below :


var uniqueProjectIds = [];
var uniqueBUs = [];
var form = document.forms[0];
var ddl = form.cmbProjects;

for(var i = 0; i < PROJECTID.length; i++)
{
    if(uniqueProjectIds[PROJECTID[i]] == null)
    {
        uniqueProjectIds[PROJECTID[i]] = [];
        ddl.options[ddl.options.length] = new Option( PROJECTNAME[i], PROJECTID[i] );
    }
    uniqueProjectIds[PROJECTID[i]].push(i);

    if(uniqueBUs[PROJECTID[i]] == null)
    {
        uniqueBUs[PROJECTID[i]] = [];
    }
    uniqueBUs[PROJECTID[i]].push(BU[i]);
}