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

ASP and HTML Select Inputs 1

Status
Not open for further replies.

ParaTrooper

Technical User
Feb 5, 2002
16
0
0
US
I am using ASP and a Access Database to view and store data on certain vehicles.

How would I dynamically load the contents of two HTML select inputs from the database using JavaScript?

The following example may make things a bit more clear:

I want the first select input to determine the contents of the second select input, i.e: if you chose to buy a Ford car, the second select will have all the cars Ford produces, or if you select Jaguar all of Jaguars cars will be options in the second select etc.

Thanks for your help,
Jim :)
 
Hi, ok first if you select "Ford" you ask the database to display all of the "Ford" vehicles.
In order to do so you'll need one field with the cars "model" and one with the "value"(if you want to send a report afterward)

Here's how a select list looks like(i'm sure you already knew, but hey i want to be sure you understand ;-))
Code:
<form method=&quot;post&quot; action=&quot;&quot; name=&quot;frm&quot;>
  <select name=&quot;lstNom&quot; size=&quot;1&quot;>
    <option value=&quot;&quot;>Choose a model</option>
    <option value=&quot;&quot;>**************</option>
    <option value=&quot;f1&quot;>Mustang</option>
    <option value=&quot;f2&quot;>Thunderbird</option>
    <option value=&quot;f3&quot;>Focus</option>
    <option value=&quot;f4&quot;>ZX2</option>
  </select>
Ok now that you have your data you have to build your list

<form method=&quot;post&quot; action=&quot;???&quot; name=&quot;frm&quot;>
<select name=&quot;lstName&quot; size=&quot;1&quot;>
<option value=&quot;&quot;>Choose a model</option>
<option value=&quot;&quot;>**************</option>
<%while not rs.EOF %>
<option value=&quot;<%=rs(&quot;value&quot;)%>&quot;><%=rs(&quot;model&quot;)%></option>
<%
rs.MoveNext
wend
%>
and you go on with your code....

p.s. you don't have to use the value if you don't need it, i thought it would be useful to put it anyway.



Have Fun...

Sharky99 >:):O>
 
I made one of these and it was to refresh the page each time you select from the first pull down menu but then I figure out a way by javascript to make it on the spot without refreshing the page but too bad I didn't do it
look if that could help

if you don't want the page to be refreshed then you can use a hidden frame that when you select &quot;Ford&quot; for example the hidden frame will go into the database and select the products for &quot;Ford&quot; and then display them into the second pull down menu.

ChouCh,
 
ChouCh,

I checked out that site. Thats what i am after without the refreshing. Im not sure what you mean about the hidden frames though. Sort of similar to:
My ASP code so far is:

The user enters the Vehicle ID, VIN, from a prior form

vin = request.form(&quot;VIN&quot;)


Then the first Select input that has the Vehicle Types, Mustang, Focus, etc...

<SELECT NAME=&quot;VEHICLE&quot; onChange=&quot;javascript:/* Do something here */&quot;>

<%
SET vehicleRS = conn.execute(&quot;SELECT DISTINCT * FROM VEHICLE_ID ORDER BY VEHICLE&quot;)
DO UNTIL vehicleRS.EOF
RESPONSE.WRITE &quot;<OPTION VALUE=&quot;&quot;&quot; & vehicleRS.FIELDS(&quot;VIN&quot;) & &quot;&quot;&quot;&quot;
IF rs.FIELDS(&quot;VEHICLE&quot;) = vehicleRS.FIELDS(&quot;VEHICLE&quot;) THEN
RESPONSE.WRITE &quot;SELECTED&quot;
END IF
RESPONSE.WRITE &quot;>&quot; & vehicleRS.FIELDS(&quot;VEHICLE&quot;)

vehicleRS.MOVENEXT
LOOP
%>
</SELECT>




The Second Input that has the Vehicle Model for each vehicle type, TP etc

<%
RESPONSE.WRITE &quot;<SELECT NAME=&quot;&quot;MODEL&quot;&quot;>&quot;
modelSTMT = &quot;SELECT VIN_MODEL FROM VEHICLE_MODEL ORDER BY VIN_MODEL&quot;
SET modelRS = conn.execute(modelSTMT)

DO UNTIL modelRS.EOF

RESPONSE.WRITE &quot;<OPTION VALUE=&quot;&quot;&quot; & modelRS.FIELDS(&quot;VIN_MODEL&quot;) & &quot;&quot;&quot;>&quot; & modelRS.FIELDS(&quot;VIN_MODEL&quot;)


modelRS.MOVENEXT
LOOP

RESPONSE.WRITE &quot;</SELECT>&quot;
%>

How would i go about implementing the non re-fresh select input without losing the information the user has input on the prior form?

Thank for your help ppl, much appreciated.
Jim :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top