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 Textboxes from Dropdown Database

Status
Not open for further replies.

stretcher012599

Programmer
Nov 26, 2005
11
US
I have the following code, it builds the arrays but it does not populate the dropdown. I'm looking to populate the dropdown from the database and based on the selection of the dropdown it populates the text boxes. Can someone please let me know what's wrong, thanks.

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="includes/conn.asp"-->
<%
dim zips(500)
dim cities(500)
dim states(500)

Set rstemp = Server.CreateObject("ADODB.Recordset")
sql="SELECT LocationID, PostalCode, LocationName, Address1 FROM tblLocation"
rstemp.open sql,objConn, 2, 2
%>
<html>
<head>
<title>Untitled Document</title>
<!-- begin zip code array -->
<script language=JavaScript>

var zips = new Array();
var cities = new Array();
var states = new Array();

<% 'first get the zip codes, put into an array for later use

If rstemp.eof then
strNoRecs="There are no entries to display"
response.end
end if
' Now lets grab all the records
alldata=rstemp.getrows

numrows=ubound(alldata,2)
fld_theid=0
fld_fldZip=1
fld_fldCity=2
fld_fldState=3
strCount=0
FOR rowcounter = 0 TO numrows

theid=alldata(fld_theid,rowcounter)
fldZip=alldata(fld_fldZip,rowcounter)
fldCity=alldata(fld_fldCity,rowcounter)
fldState=alldata(fld_fldState,rowcounter)

response.write("zips[" & strCount & "] = '" & fldZip & "'") & vbcrlf
response.write("cities[" & strCount & "] = '" & fldCity & "'") & vbcrlf
response.write("states[" & strCount & "] = '" & fldState & "'") & vbcrlf
strCount=strCount + 1

NEXT
'end zip code array
%>

function textfill(item) {
<%
for x = 0 to ubound(zips)
%>
if (item == <%=x+1%>) {
document.Form1.text1.value = '<%=cities(x)%>';
document.Form1.text2.value = '<%=states(x)%>';
}
<%next%>
}

</script>
<!-- end zip code array -->

</head>

<body>
<form name="Form1">

<select name=select1 onChange="textfill(this.selectedIndex)">
<option>Select Zip</option>
<%
for i = 0 to ubound(zips)
%>
<option><%=zips(i)%></option>
<%
next
%>
</select>
<P>
<input type=text name=text1>
<P>
<input type=text name=text2>

</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top