Solved

Coldfusion Dynamic Variable problem

Posted on 2011-03-14
6
309 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
[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
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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

738 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