PDA

View Full Version : Populate data after dropdown box is selected.


nxwhitney
02-25-2009, 12:51 AM
I am working on a performance management tool for my work, and I am needing to populate data after a drop down is selected.

The drop down consists of people's names that are pulled from a database table. Once I select that person's name, I want fields further down the page populate data from the same table.

Sorry if I seem a bit meandering, I've been staring at code too long. Can anyone point me in the right direction?

Old Pedant
02-25-2009, 02:27 AM
Two choices:
(1) Have the <FORM> there post back to itself and then fill in the other data.

(2) Use AJAX or AJAX-style coding.

Since you have more than just one or two chunks of info to fill in, I assume, I would clearly opt for (1) as the much much easier choice.

Rough code:

<%
... open your DB connection ...

person = Trim(Request("person"))

SQL = "SELECT DISTINCT name FROM peopleData ORDER BY name"
Set RS = conn.Execute SQL
%>
<form method=post>
<select name="person">
<option value="">--select a person--</option>
<%
Do Until RS.EOF
name = RS("name")
If name = person Then sel = "SELECTED" Else sel = ""
%>
<option <%=sel%> ><%=name%></option>
<%
RS.MoveNext
Loop
RS.Close
%>
</select>

<%
If person <> "" Then
SQL = "SELECT * FROM peopleData WHERE name='" & Replace(person,"'","''") & "'"
Set RS = conn.Execute( SQL )
%>
name: <%=RS("name")%>
department: <%=RS("department")%>
salary: <%=FormatCurrency(RS("salary"))%>
...
<%
RS.Close
End If
conn.Close
%>
</form>
...


You can, of course, spruce that up quite a bit.

nxwhitney
02-25-2009, 08:37 PM
Thanks! Worked out awesome and I learned quite a bit in the process! :)