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!

automatically populating an input box

Status
Not open for further replies.

janise

Technical User
May 25, 2003
161
US
I have two pages, an input form and an insert.asp page.
The input form calls the insert.asp form which submits to the database.
I am trying to populate most of the input text fields with values from the database so that the user won't have much to input into the form.
My question is how do I populate them based on a criteria.
Example, <TR>
<TD ALIGN=LEFT> <B><FONT CLASS='Arial10'>
full name<B>
</TD>
<TD ALIGN=LEFT>
<select name=&quot;fullName&quot;>
<%
sql = &quot;SELECT tblA.EmpID, * FROM tblA &quot;
set EName = safetyDB.Execute(sql)
While not fullname.EOF
%>
<OPTION value=&quot;<%=fullname(0)%>&quot;><%=fullname(1)%></OPTION>
<%
fullname.MoveNext
wend
%>
</select>
</TD>
</TR>

Based on this code, when I select a name, I would like address, city, state, zip, phone, and all data associated with fullname to be automatically populated.
How can I do this and second, should this be done on the input form page or insert page?
Thanks and I hope this question is clear
 
I will do this on the input form, leaving the insert page to deal only with the insertion.

I will do something like this (just the basic code):
Put an onchange on the select box:

<select name=&quot;fullName&quot; onchange=&quot;ChangeSelect(this)&quot;>

<script language=&quot;javascript&quot;>
function ChangeSelect()
{
document.location = &quot;inputform.asp?sid=&quot; + this.value.toString();
}
</script>

The form will then be reloaded with the sid querystring to indicate that you have changed the select box. This can be used to execute another SQL statemet that will populate the form using sid as the id of the value selected

Hope this helps

Office notice: The beatings won't stop until morale improves
 
You could load all of the address information in the select statement as well and store it in a javascript array. This way when they select the name value from the array you can use the index of the selection and take the text from the same index in the array and place it into a span, or something similar.

For Example:
Code:
<!-- Create the select statement with onChange -->
<select name=&quot;txtName&quot; onChange=&quot;document.getElementById('mySpan').innerHTML = myArray(this.selectedIndex);&quot;>
<%
Dim arrayStr
'start the loop
Do Until rs.EOF
   'output the option
   Response.Write &quot;<option>&quot; & rs(&quot;fullname&quot;) & &quot;</option>&quot;

   'add the address info to the comma delimited list, surrounded in single quotes
   arrayStr = arrayStr & &quot;, '&quot; & city & &quot;, &quot; & state & &quot;'&quot;
   rs.MoveNext
Loop
%>
<script language=&quot;javascript&quot;>
//create the array var and assign it the ASP comma delimited list, minus the extra preceding &quot; ,&quot;
var myArray = [<%=right(arrayStr,len(arrayStr-2))%>];
</script>

Now this is on the fly, so I am pretty sure it wouldn't work ther way it is, but it should be enough to give you a possible direction to look :)

-Tarwn

[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Janise, how did you create the insert.asp page I have tried but without much success

Regards

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top