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 select or text box from other select box

Status
Not open for further replies.

WebGodiva

Technical User
Jun 21, 2000
263
US
I have a database with supervisor's code and email address.

I have a form and before it can be submitted the user must pick a supervisor code. Once they do that, I want the email field populated with the correct email address from the database so the user doesn't have to input it.

Is there a way to do this? Hope this helped!
 
It is possible, but requires mixing JS and CFML when the template builds the page. This is the example I placed in the Shared Snippets for my programmers to use as an expamle. If there is a better way, I'd sure like to know it, since it has the potential to get very large with larger queries.

Hope this helps.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>
<head>
<title>Dropdown Sample</title>

<cfscript>
pets = QueryNew(&quot;parent_id, parent, child_id, child&quot;);
QueryAddRow(pets,6);

QuerySetCell(pets,&quot;parent_id&quot;,1,1);
QuerySetCell(pets,&quot;parent&quot;,&quot;Dogs&quot;,1);
QuerySetCell(pets,&quot;child_id&quot;,1,1);
QuerySetCell(pets,&quot;child&quot;,&quot;Spot&quot;,1);

QuerySetCell(pets,&quot;parent_id&quot;,1,2);
QuerySetCell(pets,&quot;parent&quot;,&quot;Dogs&quot;,2);
QuerySetCell(pets,&quot;child_id&quot;,2,2);
QuerySetCell(pets,&quot;child&quot;,&quot;Butch&quot;,2);

QuerySetCell(pets,&quot;parent_id&quot;,1,3);
QuerySetCell(pets,&quot;parent&quot;,&quot;Dogs&quot;,3);
QuerySetCell(pets,&quot;child_id&quot;,3,3);
QuerySetCell(pets,&quot;child&quot;,&quot;Jaws&quot;,3);

QuerySetCell(pets,&quot;parent_id&quot;,1,4);
QuerySetCell(pets,&quot;parent&quot;,&quot;Dogs&quot;,4);
QuerySetCell(pets,&quot;child_id&quot;,4,4);
QuerySetCell(pets,&quot;child&quot;,&quot;Sparkee&quot;,4);

QuerySetCell(pets,&quot;parent_id&quot;,2,5);
QuerySetCell(pets,&quot;parent&quot;,&quot;Cats&quot;,5);
QuerySetCell(pets,&quot;child_id&quot;,5,5);
QuerySetCell(pets,&quot;child&quot;,&quot;Fluffey&quot;,5);

QuerySetCell(pets,&quot;parent_id&quot;,2,6);
QuerySetCell(pets,&quot;parent&quot;,&quot;Cats&quot;,6);
QuerySetCell(pets,&quot;child_id&quot;,6,6);
QuerySetCell(pets,&quot;child&quot;,&quot;Mittens&quot;,6);
</cfscript>

<script language=&quot;JavaScript&quot;>
<!--
<!--- This Javascript was added by Dan S on 6/3/00, GO Pacers!! --->
<cfoutput>
function childObject(parnt,chld,data) {
this.parent = parnt;
this.child = chld;
this.data = data;
}

kids = new Array(#Evaluate(pets.recordcount)#);
<cfset rcount=0>
<cfloop query=&quot;pets&quot;>kids[#rcount#]= new childObject(#parent_id#,#child_id#,&quot;#child#&quot;);<cfset rcount=rcount+1>
</cfloop>

function fillChild() {
for (k = document.forms[0].child_select.options.length; k >= 0; k--) {
document.forms[0].child_select.options[k] = null;
}


for(i=0; i<#rcount#; i++) {
for(j=0; j<document.forms[0].parent_select.length && !document.forms[0].parent_select.options[j].selected; j++);
if (document.forms[0].parent_select.options[j].value == kids.parent) {
newItem = document.forms[0].child_select.options.length;
document.forms[0].child_select.options[newItem] = new Option(kids.data);
document.forms[0].child_select.options[newItem].value = kids.child;
if (document.forms[0].child_select.options.length == 1)
document.forms[0].child_select.options[newItem].selected = true;
}
}
}
</cfoutput>
//-->
</script>

</head>

<body onload=&quot;fillChild()&quot;>
<form>
Type of Pet:
<select name=&quot;parent_select&quot; onchange=&quot;fillChild()&quot;>
<cfoutput query=&quot;pets&quot; group=&quot;parent_id&quot;>
<option value=&quot;#parent_id#&quot;>#parent#
</cfoutput>
</select><br>
Pet Names:
<select name=&quot;child_select&quot;>
<option value=&quot;0&quot;>(temp)
</select>
</form>

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

Part and Inventory Search

Sponsor

Back
Top