Solved

Coldfusion Dynamic Variable problem

Posted on 2011-03-14
6
299 Views
Last Modified: 2012-05-11
Right, I may be missing the obvious here, but I'm stuck:

I have a page with 5 forms on it.  The forms are created dynamically from a database.  Fieldnames are generated dynamically as well - and also has dynamic jQuery linked to update price fields and so on.

Now, one of the variables is #stand_name#, then further #stand_name#_price and #stand_name#_size

Which obv. gives me:

Budget
Budget_Size
Budget_Price

OR

Gold
Gold_Size
Gold_Price

On the next page I need to be able to do a calculation based on the #stand_name#_size.

How can I do this?

As the page doesn't know what package was used, and I can't find a way of evaluating a variable within a variable.

eg

<cfset frmSize = "#form.(#form.package#)_size#">

Any ideas?

I will also need to cfset frmPrice to match the packages price as well.

Many thanks in advance.
0
Comment
Question by:jtanner
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35129022
is your input type something like this ?

<input type="text" name="#stand_name#" value="#stand_name#" />
<input type="text" name="#stand_name#_price" value="#stand_name#_price" />
<input type="text" name="#stand_name#_size" value="#stand_name#_size" />

if not can you post how it looks ?
0
 

Author Comment

by:jtanner
ID: 35129054
	<script type="text/javascript">
    $(document).ready(function() {
    <cfloop query="rs_Stands">
	    $('#<cfoutput>#stand_name#</cfoutput>_select').change(UpdateStandPrice);
	</cfloop>
    	UpdateStandPrice();
    });
    
    function UpdateStandPrice(){
	<cfloop query="rs_Stands">
    	$('#<cfoutput>#stand_name#</cfoutput>_price').text('\u00A3' + $('#<cfoutput>#stand_name#</cfoutput>_select').val());
    	$('#<cfoutput>#stand_name#</cfoutput>_size').val($('#<cfoutput>#stand_name#</cfoutput>_select option:selected').text());
    </cfloop>
    }
	</script>

Open in new window


  
                                  <hr>
                                        <div>
                                            <cfset foo = "#products#">
                                            <cfset y = split(foo,",")>
                                            <cfset rccount="0">
                                            <cfloop from="1" to="#arrayLen(y)#" index="i">
                                                <cfquery name="incProduct">
                                                    SELECT * FROM products WHERE ProductCode='#y[i]#'
                                                </cfquery>
                                                <div style="width:150px;margin:5px 5px 5px 5px;text-align:center;float:left;">
                                                    <a href="incproduct.html?pid=#incProduct.productcode#&iframe=true&width=800&height=540" rel="prettyPhoto[Products]"><img src="images/products/#incProduct.thumbnail#" alt="#incProduct.productcode# - #incProduct.productname#"></a><br/>
                                                    <span style="font-size:10px;">#incProduct.productname#</span>
                                                </div>
                                                <cfset rccount=rccount+1><cfif rccount EQ "4"><cfset rccount="0"><div class="clear">&nbsp;</div></cfif>                                                
                                            </cfloop>
                                            <div class="clear">&nbsp;</div>
                                        </div>
                                    <hr>
                                        <form action="extras.html" method="post">
                                        <div style="float:left;font-size:18px;">
                                            <cfset foo = "#price#">
                                            <cfset x = split(foo,",")>
                                            <span class="EFHead">STAND SIZE pm/2 : </span>
                                            <select name="#stand_name#_select" id="#stand_name#_select">
                                                <cfloop from="1" to="#arrayLen(x)#" index="i" step="2">
                                                    <option value="#x[i+1]#">#x[i]#</option>
                                                </cfloop>
                                            </select>
                                        </div>
                                        <div style="float:right;">
                                            <span id="#stand_name#_price">&pound;#price_from#</span>&nbsp;&nbsp;&nbsp;<input type="hidden" name="package" value="#stand_name#"><input type="hidden" id="#stand_name#_size" name="#stand_name#_size" value=""><input type="submit" id="BuyPackage" name="BuyPackage" value="Next">
                                        </div>
                                        </form>
                                        <div class="clear">&nbsp;</div>
                                    <hr>

Open in new window

0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35129128
on your action page -> form['package'] -> will give you the package which would be either GOLD, BUDGET, etc etc...

then based on your package, you would be able to get your price and size values

say your package is GOLD

form['GOLD_price']  and form['GOLD_size'] ...

so first, write a switch , to get your package, then if case if GOLD form variables which would give you the value are form['GOLD_price']  and form['GOLD_size'], if it is BUDGET form variables which will give you the value are form['BUDGET_price']  and form['BUDGET_size'] and so on....
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35129149
Something like this

<cfset Actpackage = #form['package']# />

<cfswitch expression="#Actpackage#">
	<cfcase value="GOLD">
		<cfset price = #form['GOLD_price']# />
        <cfset size = #form['GOLD_size']# />
    </cfcase>
    <cfcase value="BUDGET">
    	<cfset price = #form['BUDGET_price']# />
        <cfset size = #form['BUDGET_size']# />
    </cfcase>
</cfswitch>

Open in new window

0
 
LVL 11

Accepted Solution

by:
Brijesh Chauhan earned 500 total points
ID: 35129187
On Second thought, this should work

<cfset Actpackage = #form['package']# />

<cfset price = #form['#Actpackage#_price']# />

<cfset size = #form['#Actpackage#_size']# />

Open in new window

0
 

Author Closing Comment

by:jtanner
ID: 35129233
Thanks for this

Worked perfectly (& is better then needing a switch) :)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now