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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Creating Option List

Status
Not open for further replies.

Alabaster

Programmer
Aug 11, 2001
44
CA
I need some help with Jscript on an ASP page,
I make 5 arrays from an SQL Server and want to pick the array from an option box and populate a second option box with that array.

here is what I've done so far...

arrayA
arrayB
arrayC ... arrayE

function onOption1Change(){
strArrayName = document.myform.optionList1.value
Select Case "strArrayName"
Case "arrayA"
for(Items in arrayA){
document.myform.optionList2.options = new option(Item);
}
End Select

I may be going about this completely wrong so I am not adverse to someone telling me a better way. I just need to have this working soon.

Thanks
Peter
 
The logic of what you've done so far seems right to me.
All you need is to merge it with the recordset from the database by ASP.
That shouldn't be too difficult.

The JavaScript below is a sample. You can replace those option values, such as subchoice='first sub choice'; , choicevalue, the max number of i, etc based on your record set by using ASP.

<Script Language=JavaScript>
function populate() {
YourChoice=document.test.selectTest.options[document.test.selectTest.selectedIndex].value;
for (var i=0; i < 4; i++) {
if (YourChoice==0) {
subchoice='first sub choice';
} else if (YourChoice==1) {
subchoice='second sub choice';
} else if (YourChoice==2) {
subchoice='third sub choice';
} else {
subchoice='fourth sub choice';
}
eval(&quot;var option&quot;+i+&quot;= new Option('&quot;+subchoice+i+&quot;', 'choicevalue&quot;+YourChoice+&quot;')&quot;);
eval(&quot;document.testtarget.selectTest.options[ i ]=option&quot; + i);
}
}
</SCRIPT>
<H3>First set of array</H3>
<FORM name=test method=get action=test.htm><SELECT NAME=&quot;selectTest&quot; onChange=populate();>
<option value='' selected>Select a choice
<option value=0>First Choice
<option value=1>Second choice
<option value=2>Third choice
<option value=3>Fourth choice
</SELECT>


<P></FORM>
<HR><H3>Second of Array here</H3>
<FORM name=testtarget><SELECT NAME=&quot;selectTest&quot; multiple></SELECT>
</FORM>

Regards
 
Thank you for your response, I think I see where I went a stray (mixing VB commands in JS for start) I will give this a shot in the morning and let you know how things go.
I guess I should have kept my mouth shut when I said I can reproduce any access form in ASP. This whole filtering thing has had me pulling my hair out for a day and a half.

Thanks
Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top