ST11
07-10-2002, 03:34 PM
This is an array (javascript) that populates one drop-down depending on what the first drop-down value is:
//this JS populates the second drop-down
<!-- Begin
team = new Array(
new Array(
new Array("Please select a name", "VP"),
new Array("David", "David<dg@entertainment.com>"),
new Array("Hugh", "Hugh<hm@entertainment.com>"),
new Array("Stephen", "Stephen<sm@woodbineentertainment.com>")
),
new Array(
new Array("Please select a name", "VP"),
new Array("Tom", "Tom<tv@entertainment.com>"),
new Array("Frank", "Frank<fl@entertainment.com>")
),
new Array(
new Array("Please select a name", "VP"),
new Array("Steve", "Steve<sw@woodbineentertainment.com>")
)
);
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 -->
//This is the first drop-down, not the whole form
<select name="Dept" onChange="fillSelectFromArray(this.form.VPName, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<option value="-1">Select Your Dept.</option>
<option value="1">Administration </option>
<option value="2">Accounting </option>
<option value="3">Broadcasting </option>
</select>
//second drop-down
<!--select name="AuthBy"-->
<select name="VPName">
<option value="VP"><b><font face="Arial, Helvetica, sans-serif" size="2">Please
select a name</font></b></option>
</select>
The problem is that i am using JS for a 'Back' link,
<a href = 'javascript:history.back();'>Change Request</a>
for the next page, but when the user uses the 'Back' link, the second-dropbox never populates in IE (5.x or 6).
Anyone have an idea why? THANKS!!!!
//this JS populates the second drop-down
<!-- Begin
team = new Array(
new Array(
new Array("Please select a name", "VP"),
new Array("David", "David<dg@entertainment.com>"),
new Array("Hugh", "Hugh<hm@entertainment.com>"),
new Array("Stephen", "Stephen<sm@woodbineentertainment.com>")
),
new Array(
new Array("Please select a name", "VP"),
new Array("Tom", "Tom<tv@entertainment.com>"),
new Array("Frank", "Frank<fl@entertainment.com>")
),
new Array(
new Array("Please select a name", "VP"),
new Array("Steve", "Steve<sw@woodbineentertainment.com>")
)
);
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 -->
//This is the first drop-down, not the whole form
<select name="Dept" onChange="fillSelectFromArray(this.form.VPName, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<option value="-1">Select Your Dept.</option>
<option value="1">Administration </option>
<option value="2">Accounting </option>
<option value="3">Broadcasting </option>
</select>
//second drop-down
<!--select name="AuthBy"-->
<select name="VPName">
<option value="VP"><b><font face="Arial, Helvetica, sans-serif" size="2">Please
select a name</font></b></option>
</select>
The problem is that i am using JS for a 'Back' link,
<a href = 'javascript:history.back();'>Change Request</a>
for the next page, but when the user uses the 'Back' link, the second-dropbox never populates in IE (5.x or 6).
Anyone have an idea why? THANKS!!!!