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!

dynamic combo boxes

Status
Not open for further replies.

jvande

MIS
Jun 6, 2001
115
US
I have two combo boxes.
They get their values from a database. The second combo box relies on values from the first. So the value of the first combo box is used to query a table and get the values for the second combo box. The second combo box looks like this.

<select name=cboSecondary size=1&quot;
>
<%while not objRS.EOF
lID = clng(objRS(&quot;ID&quot;))%>
<option value=&quot;<%=lID%>&quot;><%=objRS(&quot;School_City&quot;)%>
<% objRS.MoveNext
wend
objRS.Close
set objRS.ActiveConnection = nothing
set objRS = nothing
%>

Now the problem that I am having is trying to pass the information from cboSecondary combo box. It is easy to pass the ID but, I want to pass the school_city that the end-user selects. Any help would be greatly appreciated.
 
Hey jvande,

Is that combo box a single select, or can users select more than one item from it ??

ToddWW
 
Because the solution to your situation is so different between single select lists and multiple select lists, I just want to make sure I understand you correctly. In your example.
Code:
<select name=cboSecondary size=&quot;1&quot;>
<%while not objRS.EOF
lID = clng(objRS(&quot;ID&quot;))%>
<option value=&quot;<%=lID%>&quot;><%=objRS(&quot;School_City&quot;)%>
<%    objRS.MoveNext
wend
objRS.Close
set objRS.ActiveConnection = nothing
set objRS = nothing
%>
Doesn't look like a select list that allows users to choose multiple options.

Just want to make sure before I provide a solution for you.

I hope I'm not sounding argumentative.

ToddWW :)
 
No, I want to give you any info you need. THis problem has me stumped.
 
Oh real quick, one other question.

Are you executing a JavaScript function upon submittal, or is the form just being submitted using a submit button.

ToddWW
 
No java, just asp. when submitting I am posting the info. I need to keep the values in both comboboxes.
 
Most would be stumped here because you can't store more than one value to an option in a select list. But I think we have a communication gap here.

The example you provided..
Code:
<select name=cboSecondary size=&quot;1&quot;>
<%while not objRS.EOF
lID = clng(objRS(&quot;ID&quot;))%>
<option value=&quot;<%=lID%>&quot;><%=objRS(&quot;School_City&quot;)%>
<%    objRS.MoveNext
wend
objRS.Close
set objRS.ActiveConnection = nothing
set objRS = nothing
%>
Does not look like a select list that you can make multiple selections on. But you stated that you could make multiple selections on it.

Can you confirm whether the user can select multiple School Cities before submitting the form??

ToddWW :)
 
Yes. Here is the database layout.
Tableone (which is displayed in ComboBox1)
ID Primary Key
School_Name
TableTwo (which is displayed in ComboBox2)
ID Primary Key
School_City Primary Key
These two tables are joined by a one two many relationship with ID. So the first selection will take the ID and then show all record in table two with that ID.
lID = clng(objRS(&quot;ID&quot;))%> (this is where it selects the ID)
<option value=&quot;<%=lID%>&quot;><%=objRS(&quot;School_City&quot;)%>
(This is what makes the value the School_city name instead of the ID)
 
OK, we are still having a communication problem here, so I can only make an assumption at this point or this is going to start to sound like an argument. Based on the sample code that you provided, I am going to assume that the user can make only a single selection from the list that you provided before hitting the submit key. The only reason I asked if they could make multiple selections was because you have been calling them combo boxes from the beginning. So forget that.. Let's work with the single selection list theory.

Here's what I want you to do.. Changes are in RED

<select name=cboSecondary size=&quot;1&quot;>
<%while not objRS.EOF
lID = clng(objRS(&quot;ID&quot;))%>
<option value=&quot;<%=lID%>&quot;><%=objRS(&quot;School_City&quot;)%>
<% objRS.MoveNext
wend
objRS.Close
set objRS.ActiveConnection = nothing
set objRS = nothing
%>
</select>
<input type=&quot;hidden&quot; name=&quot;city&quot; value=&quot;&quot;>

Now if you're using a JavaScript function to do some validation and then submit the form, then just place the following line in that JavaScript function just before the submit() or return true line.

formreference.city.value = formreference.cboSecondary.options[formreference.cboSecondary.selectedIndex].text

If you're not using JavaScript to validate or submit the form, you're going to need to do that. It's simple, just make this small change to the opening <form> tag where the select lists and your newly created hidden field are located.

<form action=&quot;blahblah&quot; method=&quot;blah&quot; onSubmit=&quot;return formCheck(this);&quot;>

Then between the <head></head> tags in your document, place these lines.

<script Language=&quot;JavaScript&quot;>
<!--
function checkForm(form_ref) {
form_ref.city.value = form_ref.cboSecondary.options[form_ref.cboSecondary.selectedIndex].text
return true
}
//-->
</script>


That will populate the hidden field's value with the Text of the selected option at the time of submittal. On the page that's receiving the form, a simple.. Request.Form(&quot;city&quot;) will return the city name, or the text of the option that was selected in the secondary list.

Hope this helps..

ToddWW
 
If u need to pass just the School_City u need to put them in the value field:
Code:
<option value=&quot;<%=School_City%>&quot;><%=objRS(&quot;School_City&quot;)%>
And if u need to pass multiple values u need to put the MULTIPLE word in your select tag:
Code:
<select name=cboSecondary size=&quot;1&quot; multiple>

And one question - Do u know how to deal with multiple select in the asp page witch process your information? ________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top