Skip to main content
Inspiring
November 1, 2009
Answered

Count <cfselect> values

  • November 1, 2009
  • 2 replies
  • 1351 views

Good evening all,

I have two <cfselect>s in my form, I want to count how many values the user select and save that count to my database. Anyone seen this before? I would like to accomplish this, any help is very welcome.

Thanks,

DJ Khalif

This topic has been closed for replies.
Correct answer BKBK

Suppose the fields are called select1 and select2. You could, in the action page, do something like listLen(form.select1)+listLen(form.select2). After all, a multiple selection will produce a comma-delimited list. 

2 replies

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
November 1, 2009

Suppose the fields are called select1 and select2. You could, in the action page, do something like listLen(form.select1)+listLen(form.select2). After all, a multiple selection will produce a comma-delimited list. 

djkhalifAuthor
Inspiring
November 2, 2009

BKBK,

Thanks. I do have another question:

How do I INSERT that list into SQL with same ID number for each item in list that is the same as the ID of the main table?

Thanks,

djkhalif

Inspiring
November 2, 2009

<cfquery>

insert into yourtable (id, otherfield)

select 1, ''

from some_small_table where 1 = 2

<cfloop list = "#form.something#" index = "something">

union

select distinct #id_variable#, '#something#'

from some_small_table

closing tags

BKBK
Community Expert
Community Expert
November 1, 2009

Remember the cfselect attribute multiple="yes", which enables a user to select multiple items!