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

cfselect get more data on same screen

Status
Not open for further replies.

mmaddox

IS-IT--Management
May 22, 2002
53
US
I want to select a name from a select option, and have related information show up in other boxes based on the name selected, on the same screen. I can do a second query on a second page to the get the data, but is there a way to get it on the first screen.
This code works to populate the boxes with static data when a name is selected, but is there a way to get the site and phone data related to the selected name from the query to populate the boxes?

<CFQUERY NAME=&quot;GETDATA&quot; DATASOURCE=&quot;contacts&quot;>
SELECT lastname, (lastname+', '+firstname) AS NAME, site, phone
from hlphone2
Order by Lastname
</CFQUERY>

<script type=&quot;text/javascript&quot;>
function boxes(){
document.myform.boxsite.value = &quot;site&quot;;
document.myform.boxphone.value = &quot;phone&quot;;
}
</script>

<cfForm action=&quot;fil2.cfm&quot; method=&quot;post&quot; name = &quot;myform&quot; >

<cfinput type=&quot;text&quot; name=&quot;boxsite&quot;><br>
<cfinput type=&quot;text&quot; name=&quot;boxphone&quot;><br>

<cfselect name=&quot;options&quot; onChange=&quot;boxes()&quot;>
<cfoutput query=&quot;getdata&quot;>
<option value=&quot;#getdata.NAME#&quot;>#Getdata.NAME#</option>
</cfoutput>
</cfselect>
</cfform>

Thanx for any help
 
Check the Macromedia Developers' Exchange for the custom tag CF_TwoSelectsRelated (or CF_ThreeSelectsRelated if you need that functionality).

HTH,

Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
Um, whoops. I missed your point. While the custom tag populates another select box, you want textboxes populated.

There's some code in the MM forum that demonstrates this. It basically involves populating a Javascript array, and passing the primary key of the select to a function that searches the array and pops the fields with the values needed.



Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
This code, while not exactly what you need, should give you an idea of what to do. Replace the alert() statement with statements that change the value of the textboxes.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<!--- let this list represent your query results --->
<cfset xyz=&quot;A1,A4,A9,B2,B4&quot;>
<cfset loopval=listlen(xyz)>
<html>
<head>
<title>Untitled</title>
<script language=&quot;JavaScript1.1&quot;>
ls = new Array();
<cfoutput>
<cfset counter=0>
<cfloop index=&quot;val&quot; list=&quot;#xyz#&quot;>
<cfset counter=evaluate(&quot;counter+1&quot;)>
ls[#counter#] = '#val#';

</cfloop>

function checkval() {
picked = document.blahzee.blah.selectedIndex;

thisval = document.blahzee.blah.options[picked].value;
for (x=1;x < #evaluate(&quot;loopval+1&quot;)#;x++)
{if (thisval == ls[x]){alert('You got it; it is ' + thisval);
//the commands would be something like
//document.myform.boxsite.value = '#site#';
//document.myform.boxphone.value = '#phone#';
return true;
} }



}
</script>
</cfoutput>
</head>

<body>
<form name=&quot;blahzee&quot; action=&quot;nothing&quot; method=&quot;post&quot;>
<select name=&quot;blah&quot; onchange=&quot;checkval();&quot;><cfoutput><cfloop index=&quot;val&quot; list=&quot;#xyz#&quot;><option value=&quot;#val#&quot;>#val#
</cfloop></cfoutput><option value=&quot;A2&quot;>A2<option value=&quot;Q3&quot;>Q3</select>
</form>


</body>
</html>

Sorry for the confusion.

Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
There is a tag in the Macromedia exchange that does exactly this. It's called CF_AutoPopulate. It can populate text boxes and/or hidden fields by whatever is chosen in a select box.



Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top