Click to See Complete Forum and Search --> : Auto drop Down Script Help


toastg
09-21-2003, 10:18 AM
Hi, I am looking for help altering the script located at: http://javascript.internet.com/forms/auto-drop-down.html

This script creates a drop down based on the 1st slection popultates the 2nd dropdown

I need to use this script twice on the same form. My problem is that I change the select box names on the form and then in the script but it doesn't seem to work… I also had edited the select - onchange: fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));
I replace "Team" with the new select field "name" I also change "Team" to the new "name" in the code: team = new Array(
It doesn't seem to work, is there something I am missing in either the select - onchange or script? Any help would be appreciated… thank you for your time.

96turnerri
09-21-2003, 12:29 PM
could you post ur scipt onto this thread then i can av a look?

toastg
09-21-2003, 01:27 PM
sure here is the script: I need to change the menu name from "Team" to "Location" anytime i change the "team" to location it stops working.... thanks for any help....


<!-- TWO STEPS TO INSTALL AUTO DROP DOWN:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Jerome Caron (jerome.caron@globetrotter.net) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
team = new Array(
new Array(
new Array("Saku Koivu", 39482304),
new Array("Martin Rucinsky", 34802389),
new Array("Jeff Hackett", 39823498),
new Array("Sheldon Sourray", 87587343),
new Array("Richard Zednik", 68798735),
new Array("Brian Savage", 98098509),
new Array("Stephane Robidas", 49490583),
new Array("Patrice Brisebois", 32898334),
new Array("Oleg Petrov", 92340934),
new Array("Chad Kilger", 34923409),
new Array("Benoit Brunet", 59384093),
new Array("Jan Bulis", 83948023),
new Array("Patrick Traverse", 41239812),
new Array("Jose Theodore", 98402398),
new Array("Craig Darby", 82393434),
new Array("Patric Poulin", 34290348),
new Array("Karl Dykhuis", 89092834)
),
new Array(
new Array("Mario Lemieux", 23840238),
new Array("Jaromir Jagr", 92390484),
new Array("Robert Lang", 29048203),
new Array("Alexei Kovalev", 94098230),
new Array("Jean-Sebastien Aubin", 39234923),
new Array("Kevin Stevens", 29345423)
),
null,
new Array(
new Array("Alexei Yashin", 20394802),
new Array("Daniel Alfredson", 34982039),
new Array("Marian Hossa", 92348902),
new Array("Patrick Lalime", 98203894),
new Array("Radek Bonk", 98234902)
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<FORM NAME="main">
<SELECT NAME="Make" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<OPTION VALUE="-1">Select Team
<OPTION VALUE=1>Montreal Canadiens
<OPTION VALUE=2>Pittsburg Penguins
<OPTION VALUE=3>Toronto Maple Leafs
<OPTION VALUE=4>Ottawa Senators
</SELECT>
<BR>
<SELECT NAME="Team" SIZE="5">
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
</SELECT>
</FORM>


<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 4.15 KB -->

96turnerri
09-22-2003, 05:41 PM
where u changing it to location, at the bottom where it say team change it to this

<OPTION VALUE="-1">Select Location

toastg
09-23-2003, 08:56 AM
here is how i have it now:

<SELECT NAME="RequestorsLocation" id="RequestorsLocation" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<option value="-1">[SELECT]</option>
<option value="Manhasset">Manhasset</option>
<option value="LIJ">LIJ</option>
<option value="Hillside">Hillside</option>
<option value="Schneiders">Schneiders</option>
<option value="Plainview">Plainview</option>
<option value="Syosset">Syosset</option>
<option value="Glen Cove">Glen Cove</option>
<option value="Forest Hills">Forest Hills</option>
<option value="Franklin">Franklin</option>
<option value="Other/Remote">Other/Remote</option>
</SELECT>

96turnerri
09-23-2003, 11:53 AM
ok theres nothing wrong with that, you just now need to change the options after selecting the first one, do you know how to do this?

toastg
09-23-2003, 02:13 PM
well I change anything that says "Team" to "location" which is the name of the 2nd drop down and nothing displays in the 2nd drop down. For example:

<SELECT NAME="RequestorsLocation" id="RequestorsLocation" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">

I change it to:

<SELECT NAME="RequestorsLocation" id="RequestorsLocation" onChange="fillSelectFromArray(this.form.location, ((this.selectedIndex == -1) ? null : location[this.selectedIndex-1]));">

its when i change the "team" property that it doesnt work

96turnerri
09-24-2003, 11:58 AM
why do you need to change it to team cant you just leave it as location if you do insist on changing it you will need to change all refernces to team to location

toastg
09-24-2003, 01:21 PM
actually I need to chage "Team" to location - one reason is I am trying to get 2 sets of htese menus working in one form - having the same name would be a conflict... also just for debuggin purposes down the raod - "Team" wont make much sence if someone else need to modify something....

96turnerri
09-24-2003, 05:11 PM
to change it to location you need to change all three of the 'team's to location

toastg
09-24-2003, 07:59 PM
yeah I have change all three of the "Teams" to "location but it bombs out on me....

96turnerri
09-25-2003, 04:57 AM
i may be wrong but i think it is written coded, if you know what i mean, cannot be changed, when i change it to team not location a big error come up saying cannot find file then a big list of the array

toastg
09-25-2003, 08:43 AM
yeah it will look for this js script in the header as follows:
Just note i change line2: team = new Array(
to: location = new Array(


<!-- Begin
team = new Array(
new Array(
new Array("[SELECT]"),
new Array("MH 100"),
new Array("MH 125"),
new Array("MH 145"),
new Array("MH 150"),
new Array("MH 155"),
new Array("MH 1554"),
new Array("MH 175"),
new Array("MH 200"),
new Array("MH 300"),
new Array("MH 330"),
new Array("MH 350"),
new Array("MH 400"),
new Array("MH 865"),
new Array("MH Day Ctr"),
new Array("MH Network Mgmt")
),
new Array(
new Array("[SELECT]"),
new Array("LIJ Main"),
new Array("NHP 400 Bldg"),
new Array("NHP 410 Bldg"),
new Array("NHP 420 Bldg"),
new Array("NHP Finkelstein"),
new Array("NHP Marcus Ave"),
new Array("PB3 Trailer"),
new Array("PB6 Trailer"),
new Array("Queens Day Center"),
new Array("Queens Dialysis")
),
new Array(
new Array("[SELECT]"),
new Array("Hillside Main"),
new Array("E. Sloman Lowenstein"),
new Array("Kaufman"),
new Array("L. Lowenstein"),
new Array("Littauer Bldg.")
),
new Array(
new Array("[SELECT]"),
new Array("NHP Schneiders"),
new Array("MH Schneider's at Hewlett")
),
new Array(
new Array("[SELECT]"),
new Array("Plainview Main")
),
new Array(
new Array("[SELECT]"),
new Array("Syosset Main"),
new Array("Syosset Ambulance")
),
new Array(
new Array("[SELECT]"),
new Array("Glen Cove Main"),
new Array("Oyster Bay Fam. Practice")
),
new Array(
new Array("[SELECT]"),
new Array("FH Main")
),
new Array(
new Array("[SELECT]"),
new Array("Franklin Main"),
new Array("Franklin Homecare")
),
new Array(
new Array("[SELECT]"),
new Array("Carrillon Nursing Home & Rehab"),
new Array("Center for Autism/Pain Center"),
new Array("Commack Pediatrics"),
new Array("Grandell Rehab. And Nursing"),
new Array("Gurwin Jewish Geriatric Center"),
new Array("Hauppage Main")
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End -->

96turnerri
09-25-2003, 10:18 AM
now just change thesse

<SELECT NAME="Make" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<OPTION VALUE="-1">Select Location
<OPTION VALUE=1>Montreal Canadiens
<OPTION VALUE=2>Pittsburg Penguins
<OPTION VALUE=3>Toronto Maple Leafs
<OPTION VALUE=4>Ottawa Senators
</SELECT>

toastg
09-25-2003, 12:24 PM
yeah - i change those "teams" as well and i get nothing on the second dropdown menu

96turnerri
09-25-2003, 01:01 PM
try this then

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Jerome Caron (jerome.caron@globetrotter.net) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
team = new Array(
new Array(
new Array("[SELECT]"),
new Array("MH 100"),
new Array("MH 125"),
new Array("MH 145"),
new Array("MH 150"),
new Array("MH 155"),
new Array("MH 1554"),
new Array("MH 175"),
new Array("MH 200"),
new Array("MH 300"),
new Array("MH 330"),
new Array("MH 350"),
new Array("MH 400"),
new Array("MH 865"),
new Array("MH Day Ctr"),
new Array("MH Network Mgmt")
),
new Array(
new Array("[SELECT]"),
new Array("LIJ Main"),
new Array("NHP 400 Bldg"),
new Array("NHP 410 Bldg"),
new Array("NHP 420 Bldg"),
new Array("NHP Finkelstein"),
new Array("NHP Marcus Ave"),
new Array("PB3 Trailer"),
new Array("PB6 Trailer"),
new Array("Queens Day Center"),
new Array("Queens Dialysis")
),
new Array(
new Array("[SELECT]"),
new Array("Hillside Main"),
new Array("E. Sloman Lowenstein"),
new Array("Kaufman"),
new Array("L. Lowenstein"),
new Array("Littauer Bldg.")
),
new Array(
new Array("[SELECT]"),
new Array("NHP Schneiders"),
new Array("MH Schneider's at Hewlett")
),
new Array(
new Array("[SELECT]"),
new Array("Plainview Main")
),
new Array(
new Array("[SELECT]"),
new Array("Syosset Main"),
new Array("Syosset Ambulance")
),
new Array(
new Array("[SELECT]"),
new Array("Glen Cove Main"),
new Array("Oyster Bay Fam. Practice")
),
new Array(
new Array("[SELECT]"),
new Array("FH Main")
),
new Array(
new Array("[SELECT]"),
new Array("Franklin Main"),
new Array("Franklin Homecare")
),
new Array(
new Array("[SELECT]"),
new Array("Carrillon Nursing Home & Rehab"),
new Array("Center for Autism/Pain Center"),
new Array("Commack Pediatrics"),
new Array("Grandell Rehab. And Nursing"),
new Array("Gurwin Jewish Geriatric Center"),
new Array("Hauppage Main")
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<FORM NAME="main">
<SELECT NAME="Make" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<OPTION VALUE="-1">Select Team
<OPTION VALUE=1>MH
<OPTION VALUE=2>NHP
<OPTION VALUE=3>FD
<OPTION VALUE=4>Other
</SELECT>
<BR>
<SELECT NAME="Team" SIZE="5">
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
</SELECT>
</FORM>

toastg
09-25-2003, 03:22 PM
yeah it will work as long as you leave "Team" there... I'm trying to change "team" to location

96turnerri
09-26-2003, 04:27 AM
o sorry didnt see that thought u changed it lol right on it again lol :D

96turnerri
09-26-2003, 04:32 AM
i think what it is is that location is a command thats whats messing it up, i may be wrong as im not a js expert only a beginner but that could be why

96turnerri
09-26-2003, 04:36 AM
yeap i was right :D :D :D :D :D

changed it to place and it works

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Jerome Caron (jerome.caron@globetrotter.net) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
place = new Array(
new Array(
new Array("[SELECT]"),
new Array("MH 100"),
new Array("MH 125"),
new Array("MH 145"),
new Array("MH 150"),
new Array("MH 155"),
new Array("MH 1554"),
new Array("MH 175"),
new Array("MH 200"),
new Array("MH 300"),
new Array("MH 330"),
new Array("MH 350"),
new Array("MH 400"),
new Array("MH 865"),
new Array("MH Day Ctr"),
new Array("MH Network Mgmt")
),
new Array(
new Array("[SELECT]"),
new Array("LIJ Main"),
new Array("NHP 400 Bldg"),
new Array("NHP 410 Bldg"),
new Array("NHP 420 Bldg"),
new Array("NHP Finkelstein"),
new Array("NHP Marcus Ave"),
new Array("PB3 Trailer"),
new Array("PB6 Trailer"),
new Array("Queens Day Center"),
new Array("Queens Dialysis")
),
new Array(
new Array("[SELECT]"),
new Array("Hillside Main"),
new Array("E. Sloman Lowenstein"),
new Array("Kaufman"),
new Array("L. Lowenstein"),
new Array("Littauer Bldg.")
),
new Array(
new Array("[SELECT]"),
new Array("NHP Schneiders"),
new Array("MH Schneider's at Hewlett")
),
new Array(
new Array("[SELECT]"),
new Array("Plainview Main")
),
new Array(
new Array("[SELECT]"),
new Array("Syosset Main"),
new Array("Syosset Ambulance")
),
new Array(
new Array("[SELECT]"),
new Array("Glen Cove Main"),
new Array("Oyster Bay Fam. Practice")
),
new Array(
new Array("[SELECT]"),
new Array("FH Main")
),
new Array(
new Array("[SELECT]"),
new Array("Franklin Main"),
new Array("Franklin Homecare")
),
new Array(
new Array("[SELECT]"),
new Array("Carrillon Nursing Home & Rehab"),
new Array("Center for Autism/Pain Center"),
new Array("Commack Pediatrics"),
new Array("Grandell Rehab. And Nursing"),
new Array("Gurwin Jewish Geriatric Center"),
new Array("Hauppage Main")
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<FORM NAME="main">
<SELECT NAME="Make" onChange="fillSelectFromArray(this.form.Place, ((this.selectedIndex == -1) ? null : place[this.selectedIndex-1]));">
<OPTION VALUE="-1">Select Place
<OPTION VALUE=1>MH
<OPTION VALUE=2>NHP
<OPTION VALUE=3>FD
<OPTION VALUE=4>Other
</SELECT>
<BR>
<SELECT NAME="Place" SIZE="5">
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
</SELECT>
</FORM>