/    Sign up×
Community /Pin to ProfileBookmark

Help editing JS code

Hello all,

I borrowed a bit of JS code from a website and modified it so it could handle progressive dropdown box population for four boxes. It works, but I’d like to improve it. I have no talent to read JS code so I’m basically looking for ideas on how to do what I want to do. Let me show you the code as it is today:

<SCRIPT LANGUAGE=”JavaScript”>

var Sites = new Array();
var Divisions2 = new Array();

Sites[1] = “All Sites”;
Divisions2[1] = “All Divisions”;
[23 MORE PAIRS OF SITE/DIVISION FOLLOW]

var Departments2 = new Array();
var Divisions = new Array();

Departments2[1] = “All Departments”;
Divisions[1] = “All Divisions”;
[119 MORE PAIRS OF DIVISION/DEPARTMENT FOLLOW]

var Areas = new Array();
var Departments = new Array();

Areas[1] = “All Areas”;
Departments[1] = “All Departments”;
[444 MORE PAIRS OF DEPARTMENT/AREA FOLLOW]

function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;

// Empty the second drop down box of any choices

for (var q=controlToPopulate.options.length;q>=0;q–)

controlToPopulate.options[q] = null;

if (control.name == “Division”) {

// Empty the third drop down box of any choices

for (var q=New_CorrAct.Department.options.length;q>=0;q–)

New_CorrAct.Department.options[q] = null;
}

if (control.name == “Department”) {

// Empty the fourth drop down box of any choices

for (var q=New_CorrAct.Area.options.length;q>=0;q–)

New_CorrAct.Area.options[q] = null;
}

// ADD Default Choice – in case there are no values

myEle = document.createElement(“option”) ;
myEle.value = “%” ;
myEle.text = “Select” ;
controlToPopulate.add(myEle) ;

// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement(“option”) ;
myEle.value = ItemArray[x] ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}

// End –>
</script>

What’s happening is that we have the same division or department in several sites and the boxes don’t really narrow the selections because instead of one huge array, I have three separate ones. I’d like to be able to work things around so I can use one huge array so only what’s pertinent within a site/division/department shows up.

Can someone please guide me on how to do this? Help will be greatly appreciated in the form of cyber smiles ?

Thanks for reading!

Natalia

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @NatuScape spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...