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

x
?
Solved

Coldfusion Dynamic Variable problem

Posted on 2011-03-14
6
Medium Priority
?
321 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 To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 
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 2000 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

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…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

730 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