Solved

Coldfusion Dynamic Variable problem

Posted on 2011-03-14
6
304 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
3 Use Cases for Connected Systems

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

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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