Mike Waller
asked on
loop over form field (select) options
I'm using the following code but I need to loop over each record and select the one that is in the db. however, it needs to display all the records too. how would I do that?
<CFQUERY NAME="getlinks" DATASOURCE="dns">
S sortorder
F tablename
order by sortorder asc
</CFQUERY>
<form method="post" action="page.cfm" name="sortorder">
Sort Order:<br />
<cfloop query="getlinks">
<select name="getorder" id="getorder">
<cfoutput>
<option value="#getlinks.sortorder#">#getlinks.sortorder#</option>
</cfoutput>
</select>
</form>
ASKER
actually, I need seperate select fields for each iteration.
oh, ok. do you mean then that you need X number of <select> lists, each with X number of options in it? if so, this should do it:
<cfoutput query="getlinks">
<select name="getorder#getlinks.cu rrentrow#" id="getorder#getlinks.curr entrow#">
<cfloop query="getlinks">
<option value="#getlinks.sortorder #">#getlin ks.sortord er#</optio n>
</cfloop>
</select>
</cfoutput>
the code to "select the one that is in the db" will depend on where that value is coming from (i.e. another query, url/form variable, etc) and which format that value is in (i.e. is it a single value or a delimited list of values)...
Azadi
<cfoutput query="getlinks">
<select name="getorder#getlinks.cu
<cfloop query="getlinks">
<option value="#getlinks.sortorder
</cfloop>
</select>
</cfoutput>
the code to "select the one that is in the db" will depend on where that value is coming from (i.e. another query, url/form variable, etc) and which format that value is in (i.e. is it a single value or a delimited list of values)...
Azadi
ASKER
Azadi, I need to populate each select list with all the records but select the one that's in the db.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm trying to do the following but the value does not get selected.
<CFQUERY NAME="getlinks" DATASOURCE="#application.datasource#">
S SM.*, ST.id, ST.templateNameID, ST.sitenameID
F #application.dbowner1#.site#placement#menu SM, siteNameID_templateNameID ST
W SM.stID = ST.id and ST.templateNameID = '#application.TemplateNameID#' and ST.sitenameID = '#application.siteNameID#'
order by [order] asc, SM.id asc
</CFQUERY>
<slect name="getorder" id="getorder">
<CFQUERY NAME="getlinks2" DATASOURCE="#application.datasource#">
S SM.*, ST.id, ST.templateNameID, ST.sitenameID
F #application.dbowner1#.site#placement#menu SM, siteNameID_templateNameID ST
W SM.stID = ST.id and ST.templateNameID = '#application.TemplateNameID#' and ST.sitenameID = '#application.siteNameID#'
order by [order] asc, SM.id asc
</CFQUERY>
<cfoutput>
<cfloop query="getlinks2">
<cfif getlinks2.order eq getlinks.order>
<option value="#getlinks2.order#" selected>#getlinks2.order#</option>
<cfelse>
<option value="#getlinks2.order#">#getlinks2.order#</option>
</cfif>
</cfloop>
</cfoutput>
</slect>
ASKER
Thx!
<select name="getorder" id="getorder">
<cfoutput query="getlinks">
<option value="#sortorder#">#sorto
</cfoutput>
</select>
i am not sure which record is the "one that is in the db" that you want to pre-select? what's the criteria for pre-selecting a record?
Azadi