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

Muliple inserts triggered by "checkbox" choices

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
HELP !!!!!!

List of "checkbox"'es comes from database 10 per page.
User can select one or many "checkbox"'es. Then SAVE.
I want to insert a row in the database for every "checkbox" selected .

Should I do some kind of loop based on "checkbox" selected ?

Thanks,
Lost in Code
 
Checkbox inputs are a pain because their names only get passed as form variables if they are checked; if the user does not check the box named "XXX" , then #form.XXX# does not exist on the action page.

Use the following to get what you want:

First, include a hidden parameter at the bottom to list all the checkbox names you want to run conditionals against on the action page, and set the values of the uniquely named inputs to "yes".

<!--- form --->
<form name=&quot;x&quot; action=&quot;action.cfm&quot; method=&quot;post&quot;>
1.<input type=&quot;checkbox&quot; name=&quot;ud1&quot; value=&quot;yes&quot;><Br>
2.<input type=&quot;checkbox&quot; name=&quot;ud2&quot; value=&quot;yes&quot;><Br>
3.<input type=&quot;checkbox&quot; name=&quot;ud3&quot; value=&quot;yes&quot;><Br>
<input type=&quot;submit&quot; value=&quot; go &quot;>

<input type=&quot;hidden&quot; name=&quot;udList&quot; value=&quot;ud1,ud2,ud3&quot;>
</form>

The action page then needs to CFPARAM all of those names in the udList variable to default to &quot;no&quot; so that you know that atleast the variable will exist for you to run conditionals against.

Loop through the list (from 1 to the length of the list) and set your variables. Then loop through the list again and display (or CFIF and check) your variables.

<!--- action --->
<CFLOOP from=&quot;1&quot; to=&quot;#listLen(udList)#&quot; index=&quot;i&quot;>
<CFPARAM name=&quot;form.#listGetAt(udList,i)#&quot; default=&quot;no&quot;>
</CFLOOP>

<CFOUTPUT>
<CFLOOP from=&quot;1&quot; to=&quot;#listLen(udList)#&quot; index=&quot;i&quot;>
#i#. #evaluate(listGetAt(udList,i))#<br>
</CFLOOP>
</CFOUTPUT>

Let me know if I helped.

strantheman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top