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

OPTGROUP?

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
I'm using OPTGROUP to group my options value, but i'm getting an wierd issue.

Code:
This is how it comes out:

<select name="ID">
	<option value="">Select</option>

	<optgroup label="Actuarial Science">
	<option value="67">ACTU</option>
	</optgroup>
	
	<optgroup label="Anthropology">
	<option value="7">ANTH</option>
	</optgroup>
	
	<optgroup label="Art History and Archaeology">
	<option value="50">AHIS</option>
	</optgroup>
	
	<optgroup label="Art History and Archaeology">
	<option value="10">HUMA</option>
	</optgroup>
</select>

Code:
This is how I want it to come out:

<select name="ID">
	<option value="">Select</option>

	<optgroup label="Actuarial Science">
	<option value="67">ACTU</option>
	</optgroup>
	
	<optgroup label="Anthropology">
	<option value="7">ANTH</option>
	</optgroup>
	
	<optgroup label="Art History and Archaeology">
	<option value="50">AHIS</option>
	<option value="10">HUMA</option>
	</optgroup>
</select>

This is what my code looks like:
Code:
<cfquery name="getIdentifier" datasource="#DB#">
	SELECT	 SI.ID, SI.Name as SIName, D.Department_Info_ID, D.Name as DName
	FROM     Subject_Identifier SI INNER JOIN 
			 Department_Info D ON D.Department_Info_ID = SI.Department_Info_ID
	ORDER BY DName, SIName
</cfquery>

<select name="Subject_Identifier_ID">
	<option value="">Select a Subject Identifier</option>
	
	<cfloop query="getIdentifier">
	<optgroup label="#DName#">
	<option value="#ID#">#SIName#</option>
	</optgroup>
	</cfloop>
</select>

____________________________________
Just Imagine.
 
Never mind. Figured it out. I replaced the <cfloop> with a <cfoutput query="" group=""> and then did another <cfoutput> inside. The nested cfoutput got me the grouping I needed.

:)

____________________________________
Just Imagine.
 
this will work too...

<cfoutput>
<cfloop query="getIdentifier">

<cfif getIdentifier.DName[currentrow] NEQ getIdentifier.DName[currentrow-1]>
<optgroup label="#DName#">
<option value="#ID#">#SIName#</option>
</optgroup>
<cfelse>
<option value="#ID#">#SIName#</option>
</cfif>
</cfloop>
</cfoutput>
</select>


 
You could also setup CFSELECT w/QUERY inside a CFFORM and it has all the attributes defined to generate the same output with 2 lines.

 
FALCONSEYE, hey thanks for that. I will test that on Monday when I get in the office.

safaritek, I don't like using the CFFORM. I find them to be more trouble then their worth.

____________________________________
Just Imagine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top