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

Using CFQUERY with select box

Status
Not open for further replies.

hacole

Programmer
Jan 19, 2001
16
US
I've got two <CFQUERY>s - each of which populate select boxes. How can I default one from the other onchange? Can I use JavaScript somehow?

Code:
<CFQUERY NAME=&quot;GetTaxCities&quot; DATASOURCE=&quot;#session.ORA_NAME#&quot;>
SELECT      distinct(short_desc),city,dscr,county,state,val_addr_city,val_taxauth_city
FROM        cis_city
WHERE       coy='#G_COY#'
AND         val_taxauth_city='Y'
</CFQUERY>

<CFQUERY NAME=&quot;GetTaxCounty&quot; DATASOURCE=&quot;#session.ORA_NAME#&quot;>
SELECT      distinct(short_desc),county,dscr,val_taxauth_cnty
FROM        cis_county
WHERE       coy='#G_COY#'
AND         val_taxauth_cnty='Y'
</CFQUERY>

OnChange of the PR_TAX_CITY select box, I want to default the PR_TAX_COUNTY select box where GetTaxCities.county = GetTaxCounty.county....

...

Code:
<select name=&quot;PR_TAX_CITY&quot;>
<option value=&quot;&quot;></option>
<CFOUTPUT QUERY = &quot;getTaxCities&quot;>
<CFIF (trim(getTaxCities.dscr) eq trim(#PR_TAX_CITY#)) OR (trim(getTaxCities.city) eq trim(#PR_TAX_CITY#))>
    <cfset tc_checked = &quot;selected&quot;>
<CFELSE>
    <cfset tc_checked = &quot;&quot;>
</CFIF>
<option value = &quot;#city#&quot; #tc_checked#>#city# - #dscr#
</CFOUTPUT>
</select>

<select name=&quot;PR_TAX_COUNTY&quot;>
<option value=&quot;&quot;></option>
<CFOUTPUT query = &quot;getTaxCounty&quot;>
<CFIF trim(getTaxCounty.county) eq trim(#PR_TAX_COUNTY#)>
	<CFSET tc_checked = &quot;selected&quot;>
<CFELSE>
	<CFSET tc_checked = &quot;&quot;>
</CFIF>
<option value = &quot;#county#&quot; #tc_checked#>#county# - #dscr#
</CFOUTPUT>
</select>

Anyone? Anyone? Thanks for the time and help!

Holly
 
I have something like this, one select box driving another, and I used Cold Fusion to get the queries, then Javascript to draw the boxes dynamically.

WARNING: This does not work on Mac IE5 for some reason.

<select name=&quot;stage1&quot; onChange=&quot;redirect(this.options.selectedIndex)&quot;>
<option value=&quot;&quot;>Please Select a National Test or State

<cfquery name=&quot;qryGetTest&quot; datasource=&quot;#application.SkillsTutorDSN#&quot;>
Select ID, Name from tbTest
Order by Area desc, Name
</cfquery>

<cfoutput query=&quot;qryGetTest&quot;>
<option>#qryGetTest.Name#
</cfoutput>

<select name=&quot;stage2&quot;>
<option value=&quot;&quot;>Select One <option value=&quot;&quot;>Select One <option value=&quot;&quot;>Select One <option value=&quot;&quot;>Select One
<option value=&quot;&quot;>Select One
</select>

<script language=&quot;Javascript&quot;>
var iComboIndex = 0;
var groups=document.doublecombo.stage1.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group=new Array()
group[0][0]=new Option(&quot;Please Select A Subject&quot;,&quot;<cfloop query=&quot;qryGetTest&quot;>
<cfset Group=#qryGetTest.CurrentRow#>
<cfquery name=&quot;qryGetContent&quot; datasource=&quot;#application.SkillsTutorDSN#&quot;>
Select tbTestContentArea.ReportFile, tbTestContentArea.ContentAreaID as ID, tbContentAreas.Name
from tbTestContentArea, tbContentAreas
where tbTestContentArea.ContentAreaID = tbContentAreas.ID
and tbTestContentArea.TestID = #qryGetTest.ID#
</cfquery>
<cfoutput query=&quot;qryGetContent&quot;>
<cfset Category=#qryGetContent.CurrentRow#-1>
group[#group#][#Category#] = new Option(&quot;#qryGetContent.Name#&quot;,&quot;pdf/#qryGetContent.ReportFile#&quot;);
</cfoutput>
</cfloop>

var temp=document.doublecombo.stage2

function redirect(x)
{
/*
// kluge to prevent selection of the seperator
if ( x == 9 )
{
if ( isNS() )
{
document.doublecombo.stage1.options[0].selected = true;
}
else
{
document.doublecombo.reset();
}

redirect(0);
return false;
}
*/
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++)
{
temp.options=new Option(group[x].text,group[x].value)
}
temp.options[0].selected=true
iComboIndex = x;
}

function go()
{
var url=temp.options[temp.selectedIndex].value
if ( 0 == iComboIndex )
{
alert(&quot;Please select a National Test or State&quot;);
return;
}

if (url.indexOf('.html') > -1)
{
openPDF(url);
}
else
{
openPDF(temp.options[temp.selectedIndex].value);
}

redirect(iComboIndex);
}

function mySubmit()
{
//setTimeout('document.myForm.reset()',0);
setTimeout('document.doublecombo.reset()',0);
return false;
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top