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

Checkboxes to select box

Status
Not open for further replies.

DeZiner

Programmer
May 17, 2001
815
US
I am building a point and click HTML form builder used for credit card processing. I have six checkboxes that I know the names of for credit card types (Visa, Mastercard, Amex, etc.) Once the user checks what they want to accept, these values need to be added to a select box with a name/value pair.

I assume I need to check for the existence of the checkbox, if it exists store it in a list then loop thru the list to create the dropdown....right?

<cfif isDefined('form.Visa')>
<cfset temp = listAppend(somelist, form.visa)>
</cfif>

Please assist with a code snippet for the workhorse page.

Thanks! DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Why not just have the user select visa from the select box?
From what you explained it sounds like you want the options in a select box to change based on what value a certain checkbox has, in this case the page needs to be submitted for coldfusion to handle what you want to to. If this is what you want, maybe a javascript solution would be better?



 
I need the cf to construct a drop down box based upon which cards a person wants to accept. They can click the checkbox for any combination of the six. This then needs to generate a the code to be copied and pasted into their website.

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
yes, only checked checkboxes are included by the browser when the form is submitted

i would not bother storing stuff in a list only to have to loop through it and pull stuff out again

CFPARAM is preferred over IsDefined

put these all at the top of the action page -- this aids in understanding, too, since it conveniently documents all the fields that the rest of the page will utilize

<CFPARAM NAME=&quot;form.visa&quot; DEFAULT=&quot;^no&quot;>
<CFPARAM NAME=&quot;form.diners&quot; DEFAULT=&quot;^no&quot;>
<CFPARAM NAME=&quot;form.mastercard&quot; DEFAULT=&quot;^no&quot;>

then just build the output dropdown options --

<select>
<CFIF form.visa NEQ &quot;^no&quot;>
<option value=&quot;V&quot;>Visa</option>
</CFIF>
<CFIF form.diners NEQ &quot;^no&quot;>
<option value=&quot;D&quot;>Diners</option>
</CFIF>
<CFIF form.mastercard NEQ &quot;^no&quot;>
<option value=&quot;M&quot;>Mastercard</option>
</CFIF>
</select>

the only way i would &quot;generalize&quot; this logic is if the various card names were being pulled from the database -- but then you'd already have faced the issue of generating the original checkbox names in a different manner...

rudy
 
Ummmm... why not name all the checkboxes the same, with the card name as the value. Then all the selected card names will be passed to the action page already as a comma-delimited list in the checkbox variable.

Code:
<input type=&quot;checkbox&quot; name=&quot;creditcards&quot; value=&quot;visa&quot;> Visa<br />
<input type=&quot;checkbox&quot; name=&quot;creditcards&quot; value=&quot;mastercard&quot;> MasterCard<br />
<input type=&quot;checkbox&quot; name=&quot;creditcards&quot; value=&quot;diners&quot;> Diners Club<br />
       :


Then your action page would have something like:

Code:
<cfparam name=&quot;creditcards&quot; default=&quot;&quot;>
         :

<SELECT name=&quot;acceptedcards&quot;>
<cfloop index=&quot;whichcard&quot; list=&quot;#FORM.creditcards#&quot;>
<CFOUTPUT><OPTION VALUE=&quot;#whichcard#&quot;>#whichcard#</OPTION></CFOUTPUT>
</cfloop>
</SELECT>

or, it sounds like you're assembling it as a variable to be plugged into the value of a text area... so...

Code:
<CFSET myoutput = &quot;&lt;SELECT name=&quot;acceptedcards&quot;&gt;&quot;>
<cfloop index=&quot;whichcard&quot; list=&quot;#FORM.creditcards#&quot;>
<CFSET myoutput = &quot;#myoutput#&lt;OPTION VALUE=&quot;#whichcard#&quot;&gt;#whichcard#&lt;/OPTION&gt;&quot;>
</cfloop>
<CFSET myoutput = &quot;#myoutput#&/SELECT&gt;&quot;>






Hope it helps,
-Carl
 
Whoops...

that CFPARAM should be:

Code:
<cfparam name=&quot;FORM.creditcards&quot; default=&quot;&quot;>
Hope it helps,
-Carl
 
Dang... and of course all my ampersand-&quot;lt&quot;s, ampersand-&quot;gt&quot;s and ampersand-&quot;quot&quot;s in the second loop example are displayed as <, >, and &quot; respectively. I was hoping CODE would suppress that... but now I realize it's the browser.

Ack.


How 'bout

Code:
<CFSET myoutput = &quot;&amp;lt;SELECT name=&amp;quot;acceptedcards&amp;quot;&amp;gt;&quot;>
<cfloop index=&quot;whichcard&quot; list=&quot;#FORM.creditcards#&quot;>
<CFSET myoutput = &quot;#myoutput#&amp;lt;OPTION VALUE=&amp;quot;#whichcard#&amp;quot;&amp;gt;#whichcard#&amp;lt;/OPTION&amp;gt;&quot;>
</cfloop>
<CFSET myoutput = &quot;#myoutput#&amp;lt;/SELECT&amp;gt;&quot;>
Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top