Solved

Coldfusion Dynamic Variable problem

Posted on 2011-03-14
6
296 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now