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

Populate form with item selected from DropDown Box (see pop Txt Bx it)

Status
Not open for further replies.

OutInLeftField

Programmer
Apr 30, 2002
37
US
I am trying to use this to build a drop down box of companies. When the user selects a company, I'd like to populate the form (with address, state, city, zip, etc) with the contactid (from table).

I tried this method put forth by the thread "Populating Text Boxes" but I receive an error "Object expected" on the line "<input type="text" name="some_other_name" id="txtChangeable">
". I know that this references the id of the array. Then I get the correct record from the array to populate the form.

HELP!

Thank you!
 
Code:
strCo = request("NameOfDropDown")

sql = "select * from companies_table where company_id = " & strCo

rs.open sql

if not rs.eof then
  response.write "Contact name: <input type=text name=contact value="" & rs("contact") & "">"

end if


Bastien

Cat, the other other white meat
 
Why not do it server-side? Something like this.
Code:
<%
SET Conn=Server.CreateObject("ADODB.Connection")
Conn.open yourConnectionSTring
' see if the first form was submitted
IF request.form("flag") <> "" then
'the select box was changed
'get the value of the Select
myCompanyID = request.form("mySelect")
strSql="SELECT address, city, state, zip FROM Companies " _ 
& "WHERE CompanyID=" & myCompanyID  
set rs=conn.execute(strSql)

'stuff fields into variables to populate the form with
IF not rs.eof then
   address=rs("Address")
   city = rs("city")
   state = rs("state")
   zip = rs("zip")
End If
set rs = nothing
End if

'get data to fill select
strSql="SELECT CompanyID, CompanyName From Companies"
set rs=conn.execute(strSql)
%>
<form name="frmSelect" method="post" action="<%=request.servervariables("SCRIPT_NAME")%>">
<input type="hidden" name="flag" value="1">
<Select name="mySelect" OnChange="SubmitTheForm()">
<%IF not rs.eof then
do while not rs.eof
CompanyID=rs("AddressID")
CompanyName=rs("CompanyName")%>
<option value="<%=CompanyID%>" <%if CompanyID=myCompanyID then%>SELECTED<%end if%>><%=CompanyName%></option>
<%
rs.movenext
loop
%>
set rs=nothing
</form>
<script language="vbscript">
Sub SubmitTheForm()
frmSelect.Submit()
End sub
<script>
<!--Your other form would go down here somewhere-->

<%conn.close
set conn=nothing%>
 
I understand what you mean on the second method but is there a way to do this on the same page in real time? I select a company from the drop down box and presto! the form fields are populated with the record fields related to the identity field pertaining to the company's "contactid" (Identity column of table).


what does "<form name="frmSelect" method="post" action="<%=request.servervariables("SCRIPT_NAME")%>">"
do?
Does this make the page self calling?
 
Even though I asked the supplemental questions about it, I will try to adapt the second code to see if this works...

Thank you...
 
<form name="frmSelect" method="post" action="<%=request.servervariables("SCRIPT_NAME")%>">"

This posts the form to the same page you're using. The OnChange event of the Select fires off the submission of the form when it's changed.
 
If you want to do this in "real time", then you would need to pass all the data to the client and use javascript to manipulate the arrays to populate the text boxes


Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top