PDA

View Full Version : Dropdown dynamic fill to pull from DB


PaulyWolly
08-30-2005, 07:10 PM
I really want to be able to highlight a pulldown entry and once I highlight the drop-down entry I want to see info appear in the other form fields on the form. The other form fields are all the info from the same record as was grabbed from the highlighted pull-down.

=================

<%
set conn=server.CreateObject ("adodb.connection")
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/ASP/project1/Employee_access.mdb") & ";Persist Security Info=False"
conn.Open connect

Set rs=Server.CreateObject("adodb.recordset")
strSQL = "SELECT employee_ID, firstName + ' ' + lastName as Name FROM employee_access ORDER by lastName"
rs.Open strSQL, conn
%>
<form id="form" type="get" action="pass_values_form.asp">
<SELECT name="user">
<%
Do until rs.EOF
%>
<option value="<%= rs("employee_ID")%>"><%=rs("Name")%></option>
<%
rs.movenext
loop
rs.close
%>
</SELECT>

<input type=submit value="Submit!">

</form>


=======================

The above works for me to submit to a new page or even to the same page.
I see in the URL: http://pass_values_form.asp?user=94
When I highlight an entry and click SUBMIT, the 'user' has become the 'employee_ID' I want the info in the drop down to automatically pull the data from the DB when the entry in the drop-down is highlighted.

I want to use this as the info I need to pass to the SQL query to pull the rest of the data fom the database to fill in the rest of the fields in my page.

This is a response I got from someone in the ASP section:
Secondly, IAre you trying to dynamically load the second section? << yes I am >>
In order for this to work with pure ASP they MUST submit the form for section 2 to populate. If you don't want them to have to submit after selecting from the drop down then you will need to use javascript.

Yes! I want to dynamically load the section to populate for Section 2. How do I set up the javascript to do this? I don't want them to submit the form until they have highlighted the drop-down entry, and then made a choice as to whether they want to keep the entries that have come up from the selection or whether to edit those entries, then re-submit back to the DB to update the DB.

Zee
09-03-2005, 02:23 PM
Simply add an event handler to the select object,


<select name="user" onchange="location.href = 'somepage.asp?someVar=' + escape(this.options[this.selectedIndex]);">


and in 'somepage.asp', use 'someVar' in your query.

Regards