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

This has probably been asked a hund

Status
Not open for further replies.

streborr

IS-IT--Management
Jan 16, 2002
98
This has probably been asked a hundred+ times and I've search this site for quite a while with no real luck.
(but I did learn other things)

When a user chooses an option in a dropdown box, populated from a db, I would like other fields on the form to be filled in automatically from information in the db.

When the user chooses a distributor from the dropdown, the Region, Number and Sales Rep associated with that distributor would be entered automatically on the form.

This information all comes from the same table.

Any and All help is gratefully appreciated!
Rick
 
The methods would be different depending on how you've built your form. Are they data bound controls, or are you populating them through code?
 
I'm only using one dropdown thats being populated through code.

<%
....stuff

rs.Open Source, ConnectionString
rs.movefirst
%>

<select size=&quot;1&quot; name=&quot;Dist&quot;>
<option value=&quot;&quot;>Select Distributor</option>
<%
Do while not rs.eof
Response.write &quot;<option value='&quot; & trim(rs(&quot;dist_name&quot;)) & &quot;'>&quot;
Response.write trim(rs(&quot;dist_name&quot;))
Response.write &quot;</option>&quot;
rs.MoveNext
Loop
rs.close
set rs = nothing
%>
</select>
 
Assuming that &quot;dist_name&quot; can be used to retrieve a unique record you can simply retrieve that record into a recordset. Assuming you submitted the form in which you have the above code with the method POST, and also assuming that the &quot;dist_name&quot; field is a numeric data type, on your next page you would just build your &quot;Source&quot; query string using the value the user selected:

Source = &quot;select * from [your table name] where dist_name = &quot; & Request.Form(&quot;Dist&quot;)

Then you would open the new recordset using that &quot;Source&quot; string and you could retrieve values out of it using rs(&quot;<some field name&quot;).

If what you were really looking for was to do this without the user having to &quot;SUBMIT&quot; the web page then you will either need to get into client-side data access (very messy and fraught with peril, though it can prove useful in some cases), or you can &quot;trick&quot; the user by doing some stuff behind the scenes (I've become rather fond of using hidden frames to submit information back to the server without the user seeing it, and then using inline javascript in the returned hidden page to populate fields on the visible form with the returned data).
 
The dropdown is populated when the page first loads.
I would be using the rs(&quot;dist_name&quot;) in the query to retrieve the information for the other fields on the form.

The information is returned to the same page and when all the fields are filled in the user hits the submit button to add to the db.

Thanks for your help
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top