Jimmy Goodson
Jimmy Goodson

Reputation: 65

Concatenate form element name with coldfusion counting variable

I'm trying to access individual form elements within a cfquery tag using the form.elementName + countingVariable. Can someone tell me what the syntax is to do this properly.

<form>
<select name="SetID0">
<option></option>
...
</select>
</form>

<cfquery>
<cfqueryparam value="#"form.SetID & #i#"#" CFSQLType="CF_SQL_CHAR">,
</cfquery>

I know there may be a better way of doing this like creating a list and I'm open to those suggestions but I'd like to know if what I'm trying to do now is possible.

Upvotes: 2

Views: 297

Answers (2)

James A Mohler
James A Mohler

Reputation: 11120

First change the pull-down menus

<form>
<select name="SetID" multiple>
  <option></option>
  ...
</select>
</form>

There are UI widgets that make this type of pulldown menu very clean. Consider Select2

Then change the query

<cfquery>
   fieldname IN  (
     <cfqueryparam value="#form.SetID#" CFSQLType="CF_SQL_CHAR" list="yes">
     )
</cfquery>

Upvotes: 0

Matt Busche
Matt Busche

Reputation: 14333

You're mostly there

<cfqueryparam cfsqltype="cf_sql_char" value="#form['setID' & i]#">

Upvotes: 3

Related Questions