Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate drop down in new page

Status
Not open for further replies.

rtnMichael

Programmer
Aug 5, 2002
152
US
Hey, I want to populate a drop down, not through a DB, but from an array through a variable chosen from the previous page. I know how to do it when it's on the same page with an array, but I'm having trouble getting it to run on another page.

Here's what I have when it's on the same page:

team = new Array(
new Array(
new Array("door","door"),
new Array("window","window"),
new Array("carpet","carpet")
),
new Array(
new Array("brown","brown"),
new Array("red","red"),
new Array("blue","blue")
),
new Array(
new Array("house","house")
)
);

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var x, j;
var prompt;

// empty existing items
for (x = selectCtrl.options.length; x >= 0; x--) {
selectCtrl.options[x] = 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 (x = 0; x < itemArray.length; x++) {
selectCtrl.options[j] = new Option(itemArray[x][0]);

if (itemArray[x][1] != null) {
selectCtrl.options[j].value = itemArray[x][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}

Select Option <SELECT NAME=&quot;option&quot; size=1 onchange=&quot;fillSelectFromArray(this.form.gotoption, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));&quot;>
<option selected value='-1'>Select Option...</option>
<option value = 'Option1'>Option1</option>
<option value = 'Option2'>Option2</option>
<option value = 'Option3'>Option3</option>
</select>

<TD><SELECT NAME=&quot;gotoption&quot; SIZE=&quot;1&quot;>
<OPTION selected value='-1'>None</OPTION>
<OPTION>                  </OPTION>
<OPTION>                      </OPTION>
</SELECT>


So Option1 gives me:
door
window
carpet

I just want to get the drop down to populate in the next page. How would I do that???

Thanks
Mike
 
Have your next page use the same code and call your fill functions from the body onLoad event based on the values passed from the previous page (Request collection)

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
but what values would I pass? Would I do this again:

Select Option <SELECT NAME=&quot;option&quot; size=1 onchange=&quot;fillSelectFromArray(this.form.gotoption, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));&quot;>
<option selected value='-1'>Select Option...</option>
<option value = 'Option1'>Option1</option>
<option value = 'Option2'>Option2</option>
<option value = 'Option3'>Option3</option>
</select>

<TD><SELECT NAME=&quot;gotoption&quot; SIZE=&quot;1&quot;>
<OPTION selected value='-1'>None</OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
</SELECT>


I've been at this all day long, maybe I'm not seeing this very clear. I tried to do something...maybe like 6 hours ago :eek:)...with the body onLoad, but didn't get anywhere. How would the function know exactly what index of the array to get?
 
ok, now I have the arrays being populated, but the onload tries to access it before it's actually populated. I bring over the &quot;option&quot; value from the previous page and do a:

set optionchosen = Request(&quot;option&quot;)

at the top of the page, but before that can actaully take place, the onload tries to grab the array when it hasn't even been made yet.

here's what I have:

if(optionchosen == &quot;Option1&quot;)
{
team = new Array(
new Array(
new Array(&quot;door&quot;,&quot;door&quot;),
new Array(&quot;window&quot;,&quot;window&quot;),
new Array(&quot;carpet&quot;,&quot;carpet&quot;)
)
);
}

else if(optionchosen == &quot;Option2&quot;)
{
team = new Array(
new Array(
new Array(&quot;brown&quot;,&quot;brown&quot;),
new Array(&quot;red&quot;,&quot;red&quot;),
new Array(&quot;blue&quot;,&quot;blue&quot;)
)
);
}

else if(optionchosen == &quot;Option3&quot;)
{
team = new Array(
new Array(
new Array(&quot;house&quot;,&quot;house&quot;)
)
);
}

<body onload='fillSelectFromArray(document.form3.gotoption, team[0])'>

and the error I get is that &quot;team&quot; is undefined. I do an alert on the &quot;optionchosen&quot; right before the above code, and it gives me the full path of the page being opened, but later in the code, I do error checking and the &quot;optionchosen&quot; variable has the right value...I don't understand, is the onload running way before anything else, even the &quot;set&quot; up at the top?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top