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

Dynamic form with CF- populate other fields with first?

Status
Not open for further replies.

ironyx

Technical User
Joined
Nov 13, 2001
Messages
134
Location
US
I don't know if it's something too wacky, but, I wanted to use a dynamic drop down as the first field and then have it generate the value in the other fields. I have tried to use a second query from the first field but it doesn't recognize it. Does anyone have any ideas? Sample of the code I used in the form:
<form method=&quot;post&quot; action=&quot;<cfoutput>#MM_editAction#</cfoutput>&quot; name=&quot;index&quot;>
<table align=&quot;center&quot;>
<tr valign=&quot;baseline&quot;>
<td nowrap align=&quot;right&quot; width=&quot;105&quot;>Username:</td>
<td width=&quot;221&quot;>
<select name=&quot;select&quot;>
<cfloop query=&quot;index&quot;>
<option value=&quot;<cfoutput>#index.Username#</cfoutput>&quot; <cfif (#index.Username# EQ # Reverse(index.Username) #)>SELECTED</cfif> ><cfoutput>#index.Username#</cfoutput></option>
</cfloop>
</select>
</td>
</tr>
<tr valign=&quot;baseline&quot;>
<td nowrap align=&quot;right&quot; width=&quot;105&quot;>First Name:</td>
<td width=&quot;221&quot;>
<input type=&quot;text&quot; name=&quot;fname&quot; value=&quot;<cfoutput query=&quot;indexName&quot;>&quot;#fname#&quot;</cfoutput>&quot; size=&quot;32&quot;>
</td>
</tr>
<tr valign=&quot;baseline&quot;>
<td nowrap align=&quot;right&quot; width=&quot;105&quot;>Last Name:</td>
<td width=&quot;221&quot;>
<input type=&quot;text&quot; name=&quot;lname&quot; value=&quot;<cfoutput query=&quot;indexName&quot;>&quot;#lname#&quot; </cfoutput>&quot; size=&quot;32&quot;>
</td>
 
//**** JUST CHANGE THE NAMES AND THIS SHOULD WORK SMOOTHLY.
//*** you put this first chunk of code on top of your
//*** search page

<CFQUERY name=&quot;FirstOptions&quot; Datasource=&quot;DynoRunEX&quot;>
Select * From RunData
</CFQUERY>

<CFLOOP index=&quot;x&quot; From = &quot;1&quot; to = &quot;#FirstOptions.recordcount#&quot;>
<CFQUERY name=&quot;Opt#x#&quot; datasource=&quot;DynoRunEX&quot;>
Select *
From RunData
Where PriKey = #FirstOptions.PriKey[x]#
</CFQUERY>
</CFLOOP>


<SCRIPT Language=&quot;JavaScript&quot;>
function updatesel(form)
{
form.Two.length = 1;
form.Two.selectedIndex = 0;
choice = form.One.options[form.One.selectedIndex].value;
<CFLOOP Index=&quot;count&quot; from=&quot;1&quot; to=&quot;#FirstOptions.recordcount#&quot;>
<CFOUTPUT>
if (choice == &quot;#FirstOptions.make[count]#&quot;)
{
<CFLOOP index=&quot;x&quot; From=&quot;1&quot; to=&quot;#Evaluate('Opt#count#.recordcount')#&quot;>

(form.Two.length)++;
form.Two.options[form.Two.length - 1].text = &quot;#Evaluate('Opt#count#.Model[x]')#&quot;;
form.Two.options[form.Two.length - 1].value = &quot;#Evaluate('Opt#count#.Model[x]')#&quot;;

</CFLOOP>
}
</CFOUTPUT>
</CFLOOP>
}
</script>

************************************************************
//**** THESE WILL CREATE THE DROP DOWN BOXES
//**** PASTE THIS IN THE SAME EARCH PAGE

<FORM METHOD=&quot;POST&quot; ACTION=&quot;look2.cfm&quot; NAME=&quot;myform&quot;>
SEARCH BY:<BR>
Make: <select name=&quot;One&quot; onChange=&quot;updatesel(this.form)&quot;>
<option value = &quot;%&quot;>All</option>
<cfoutput query=&quot;FirstOptions&quot; group=&quot;Make&quot;>
<option value = &quot;#Make#&quot;>#Make#</option>
</cfoutput></select>

Model:</font></b>
<select name=&quot;Two&quot; width=&quot;250&quot; >
<option value = &quot;%&quot;>All</option>
<cfloop index=&quot;x&quot; from=&quot;1&quot; to=&quot;6&quot;>
<cfoutput>
<option value = &quot; &quot;>000000</option>
</cfoutput></cfloop></select>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;SEARCH&quot;>
</form>

*********************************************************
//**** PASTE THIS ON YOUR RESULTS PAGE

<CFQUERY NAME=&quot;GetResults&quot; DATASOURCE=&quot;DynoRunEx&quot;>
SELECT * FROM rundata WHERE 1 =1

<cfif #form.One# NEQ &quot;All&quot;>
AND RunData.Make LIKE '%#One#%'
</cfif>
<cfif #form.Two# NEQ &quot;All&quot;>
AND Rundata.Model LIKE '%#Two#%'
</cfif>

<cfif #form.SearchYear1# NEQ &quot;All&quot;>
AND #Form.SearchYear1# BETWEEN Rundata.FirstYear and Rundata.LastYear
</cfif>
</cfquery>
 
I appreciate you taking the time to answer, and I have to apologize first for not being clear. I was trying to do a single page form that allowed the user to select Username from a drop down and then it automatically populates the first name and last name text fields with what it thinks should be correct. Then they can hit submit at the bottom of the form and it enters a single record. Maybe I am trying to get to much function out of a single item! Well, thanks anyway!
Va :o)
 
One way is to have the form submit the value of the username on the OnChange event of the select to a hidden frame -- the hidden frame can do a quick query for the name and populate the fields. This isn't really all that complicated. Take a look at this site :
This may give you an idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top