Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to set cfinput as variable?

Posted on 2008-10-23
8
Medium Priority
?
283 Views
Last Modified: 2013-12-24
Im trying to add some <cfif> statements to my <cfform> via radio button so if someone selects radio button (A) they will see this, if they select radio button (B) they will see something different.

If radio button is not the best way to do this what other option do I have to have an action based event allowing different options for different selections.
<cfparam name="billing_info" type="radio" default="pay_credit">
	Check <cfinput name="billing_info"  type="radio" value="pay_check" />
	Purchase Order <cfinput name="billing_info"  type="radio" value="pay_po" /> 
	Bill Agency <cfinput name="billing_info"  type="radio" value="pay_agency" />
	Voucher <cfinput name="billing_info"  type="radio" value="pay_voucher" />
	Credit Card <cfinput name="billing_info"  type="radio" value="pay_credit" checked="yes"/></td>
    </tr>
  <tr>
    <td colspan="6"><cfif billing_info eq "pay_check">Check <cfelse> -- </cfif></td>

Open in new window

0
Comment
Question by:tribalboy3000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 
LVL 10

Expert Comment

by:Mr_Nil
ID: 22794890
Remember that ColdFusion is a server-side technology.  What you're trying to do is Client-side.

You would need to enable/disable or make visible/invisible additional fields using javascript via the onChange attribute on the check boxes.  
0
 

Author Comment

by:tribalboy3000
ID: 22796171
Can I have an example of the javascript?
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 2000 total points
ID: 22818725
try something like this

<cfparam name="billing_info" default="pay_credit">
<cfset payList="pay_check,pay_po,pay_agency,pay_voucher,pay_credit">
<script>
function doPay(f) {
for(var i=0;i<f.length;i++) {
      if(f[i].checked) {
            document.getElementById(f[i].value).style.display='inline';      
      }
      else {
            document.getElementById(f[i].value).style.display='none';      
      }
}
}
</script>
<cfoutput>
<tr>
<td align="left" width="25%">
<form>
<cfloop list="#payList#" index="ii">
<nobr>
<input name="billing_info" id="billing_info" type="radio" value="#ii#" onclick="doPay(billing_info)"
      <cfif variables.billing_info is ii> checked</cfif> />
#ucase(listlast(ii,"_"))#
</nobr>
<br>
</cfloop>
</form>
</td>

<td align="left">
<cfloop list="#payList#" index="ii">
<div id="#ii#" style="display:<cfif variables.billing_info is ii>inline<cfelse>none</cfif>;">
this is the <b>#ii# payment method</b><br>
put appropriate form fields in here<br>
you can invoke a component that displays the correct fields<br>
cfinvoke component="???" method="getPayFields">
      cfinvokeargument name="payType" value="#ii#"
/cfinvoke
</div>
</cfloop>
</td>
</tr>
</cfoutput>
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

Author Comment

by:tribalboy3000
ID: 22824416
Can you please add to your example by showing me an instance of the different form fields that show up when the radios button are selected. I will not be using the component example I need to keep this as simple as possible.
0
 

Author Comment

by:tribalboy3000
ID: 22826097
Okay after some trial and error got the code to work the way I wanted it, Here is the end result.
<cfloop list="#payList#" index="ii">
<nobr>
<cfinput name="billing_info" id="billing_info" type="radio" value="#ii#" onclick="doPay(billing_info)" checked="no" required="yes"/>
#ucase(listlast(ii,"_"))#</nobr>
<br>
</cfloop></td>
    </tr>
  </table>
<div id="pay_check" style="display:<cfif variables.billing_info is pay_check>inline<cfelse>none</cfif>;">
  <table width="70%" border="0" cellpadding="5" cellspacing="3" bgcolor="##FFFFFF" class="body">
    <td colspan="6">Check </td>
  </table>
</div>
<div id="pay_po" style="display:<cfif variables.billing_info is pay_po>inline<cfelse>none</cfif>;">
  <table width="70%" border="0" cellpadding="5" cellspacing="3" bgcolor="##FFFFFF" class="body">
    <td colspan="6">Purchase Order </td>
  </table>
  </div>
<div id="pay_agency" style="display:<cfif variables.billing_info is pay_agency>inline<cfelse>none</cfif>;">
  <table width="70%" border="0" cellpadding="5" cellspacing="3" bgcolor="##FFFFFF" class="body">
    <td colspan="6">Bill Agency </td>
  </table>
  </div>
<div id="pay_voucher" style="display:<cfif variables.billing_info is pay_voucher>inline<cfelse>none</cfif>;">
  <table width="70%" border="0" cellpadding="5" cellspacing="3" bgcolor="##FFFFFF" class="body">
    <td colspan="6">Voucher</td>
 </table>
 </div>

Open in new window

0
 

Author Closing Comment

by:tribalboy3000
ID: 31509423
Thanks for the code samples, it really helped.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 22826545
I'm glad you got it and good luck ...
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question