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!

auto populate from Database

Status
Not open for further replies.

spruce009

MIS
May 12, 2003
33
US
I have an access database with a vendor table. I am offering on my web form, a drop down list with the vendor names. Being new to javascript, I was hoping someone could tell me the best way to autopopulate the remaining text fields (Address, city, etc.) based on the selection from the drop down list. Thanks for your help.
 
What language are you using on the server-side?

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
If you're using ASP to write the values from the database, you could do something like this:
Code:
<script>
[green]//Object template to store the extra data[/green]
function objFields(city,state,zip){
  this.city  = city;
  this.state = state;
  this.zip   = zip;
}
[green]//Function to fill the other form fields[/green]
function fillFields(i){
  document.formName.city.value  = selectArray[i].city;
  document.formName.state.value = selectArray[i].state;
  document.formName.zip.value   = selectArray[i].zip;
}
var selectArray = new Array();
[COLOR=black yellow]<%[/color]
[green]'ASP to fill a JavaScript array with objects
'that hold the extra data[/green]
If Not rsSelectOptions.BOF Then
  rsSelectOptions.MoveFirst
End If
Do While Not rsSelectOptions.EOF
  Response.Write "selectArray[selectArray.length]=new objFields('"
  Response.Write Replace(rsSelectOptions.Fields("City")&"","'","\'")
  Response.Write "','"
  Response.Write Replace(rsSelectOptions.Fields("State")&"","'","\'")
  Response.Write "','"
  Response.Write Replace(rsSelectOptions.Fields("Zip")&"","'","\'")
  Response.Write "');" & vbCrLf
  rsSelectOptions.MoveNext
Loop
[COLOR=black yellow]%>[/color]
</script>


Code:
<select onchange="fillFields(this.selectedIndex)">
[COLOR=black yellow]<%[/color]
[green]'ASP to fill the select list[/green]
If Not rsSelectOptions.BOF Then
  rsSelectOptions.MoveFirst
End If
Do While Not rsSelectOptions.EOF
  Response.Write "<option value="""
  Response.Write Server.HTMLEncode(rsSelectOptions.Fields("VendorID")&"")
  Response.Write """>"
  Response.Write Server.HTMLEncode(rsSelectOptions.Fields("VendorName")&"")
  rsSelectOptions.MoveNext
Loop
[COLOR=black yellow]%>[/color]
</select>

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
I am using ASP to connect to an Access database. I will give this a try and see what happens. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top