[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 124
  • Last Modified:

Passing Arrays via URLs

I am creating a calculator program that allows a user to enter multiple entries and does extensive calculations after each entry and upon final entry. Upon final entry, I would like to not only display the results, but also all Input entries that the user typed.  I am currently using a form to enter data and a second program to do running/final calculations.  I can't seem to get an array to hold each entry and pass back and forth between programs for the final output.   The final calculations are correct, I just can't display all of the user entries.   can someone please give me a suggestion?  Thanks, Rhonda  
0
USNRetired
Asked:
USNRetired
2 Solutions
 
vickerleungCommented:
Rhonda,

For the storage of all the entries, I suggest the following method

Using a string to store it.

Say for an example

When the user have the following entries

1 + 2 =
* 3 =
/ 4 =

somthing like this
then you can store it in a single variable like

stored_entry = "1+2=|*3=|/4"
here I use the "|" as a delimiter

If you are using a HTML form to pass the thing
You can declare the variable by

<input name="stored_entry" type="hidden">

Hope you got my idea
Vicker
0
 
USNRetiredAuthor Commented:
Thanks Vicker,
  Let me give a sample code and see if you might have another idea.
Input screen:

<cfform name="CalcForm" onsubmit="return isValidForm(CalcForm)" action="PAB_calc.cfm" method="get">
<cfoutput>tot-income = #url.tot_income#</cfoutput>
  <table borderColor="#808000" borderColorDark="#808080" cellPadding="10" width="100%"
  borderColorLight="#c0c0c0" border="3">
    <cfoutput>
      <Input Type="Hidden" Name="payperiods" value="#url.payperiods#" >
      <Input Type="Hidden" Name="tot_percent" value="#url.tot_percent#" >
      <Input Type="Hidden" Name="tot_dollar" value="#url.tot_dollar#">
      <Input Type="Hidden" Name="systype" value="#systype#">
            <Input Type="Hidden" Name="tot_income" value="#url.tot_income#" >
<Input Type="Hidden" Name="tot_agency_match" value="#url.tot_agency_match#" >
      </cfoutput>
      <tr>
      
      <td>
      <p><b><font face="Arial"
      color="#000080" size="4">Compute Makeup Contributions to 401K systems</font></b></td>
    </tr>
    <tr align="center">
      <td vAlign="top" align="left" width="100%" color="#000080"><p><font face="Arial" color="#000080">
            <font face="Arial" color="#000080">Enter your basic Pay $:
          <input size="10" maxlength="7" name="income" value="<cfoutput>#url.income#</cfoutput>" ><!---onChange="return isDollarAmt(this)" > --->
</font></td></tr><tr> <td vAlign="top" align="left" width="100%" color="#000080"><p>
        <font face="Arial" color="#000080">Enter percentage of basic pay that you wish to compute:
            <input maxLength="2" size="2" name="cont_percent" value="0" onChange="return isValidContPercent(CalcForm)">
            %;&nbsp;<br>
          for each pay period.</font></p>
        <p align="left"> <font color="#000080" face="Arial"><strong><center>or &nbsp;<br></center></strong></font></p>
        <p><font face="Arial" color="#000080">Enter the dollar amount  $
       <input size="10" maxlength="7" name="payperiod_amt" value="0"> for each pay period.</font></p><p></p>  </td>
    </tr><tr> <td vAlign="top" align="left" width="100%" color="#000080"><p>
      <p><font face="Arial" color="#000080">Enter the number of pay periods:
          <input maxLength="2" size="2" name="period" value="0" onChange="return isNumberGE0(this)">
      </font></p></td>
    </tr><tr><td>
      <p><font face="Arial" color="#000080">Enter amount of contributions already made to other 401K systems $
       <input size="10" maxlength="7" name="other_amt" value="0"> </font></p>
      <p><font color="#000080" face="Arial">Enter all Matching contributions made to the other 401K Accounts $
          <input size="10" maxlength="7" name="umatch_amt" value="0"> </font></p>
   <tr align="center">
      <td vAlign="top" align="left" width="100%" color="#000080"><p><font face="Arial" color="#000080">If you have more than one amount for mulitiple pay periods, Click the &quot;Enter more Pay Period Information&quot; button. When you have entered all pay periods that you want to compute, Click on the &quot;Calculate&quot; button.
        </font></p></p>
      <p>
              <INPUT TYPE="submit" name="add" VALUE="Enter more Pay Period Information" >
        <input type="submit" name="calculate"  value="Calculate">
        <INPUT TYPE="reset" VALUE="Reset"></TD>

  </p></td>
    </tr>            
  </table>
</cfform>


----------------Second program that does the calculations and returns to the form for more input------------------------
-------------I've only included the section that calculates the multiple entries and keeps running totals------------------
------------When the user is finished entering all data, there are final total calculations done and displayed-------------
-------- I need an array (or some simple way) to pass ALL input values to the final display page.  They could enter-------
-------from 1 to as many entries as they need to.  This would probably be a max of 10 screen entries, but  ------------------
--------mutiple fields.  So, I need to carry a table of maybe 6 fields, 10 different values, plus all totals ----------------------
-------This is why I was looking to pass an array.  Thanks-------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>401K Calculator, Projecting Account Balance, Results</TITLE>
</HEAD>
<cfparam name="form.systype" default="">
<cfparam name="form.cont_percent" default=0>
<cfparam name="form.income" default=0>
<cfparam name="form.payperiod_amt" default=0>
<cfparam name="form.other_amt" default=0>
<cfparam name="form.period" default=0>
<cfparam name="form.tot_income" default=0>

<cfoutput>

form.systype = #form.systype#
form.cont_percent = #form.cont_percent#
form.income = #form.income#
form.payperiod_amt = #form.payperiod_amt#
form.period = #form.period#
form.uniform_amt = #form.other_amt#
form.tot_dollar = #tot_dollar#
form.tot_percent = #form.tot_percent#
form.tot_income = #form.tot_income#
</cfoutput>

<cfoutput>

<cfset tot_income = #form.tot_income# + #form.income#>

     <cfset tot_dollar = #form.tot_dollar# + (#form.payperiod_amt# * #form.period#)>
       <cfset percent = form.cont_percent / 100>
     <cfset tot_percent = form.tot_percent + ((form.income * percent) * form.period)>
       <cfset tot_uniform_amt = form.uniform_amt>
      
       <cfset tot_income = form.tot_income + (form.income * form.period)>
             <cfset percent4 = 4 / 100>
      <cfset percent5 = 5 / 100>
      <cfset percent3 = 3 / 100>
      <cfset percent2 = 2 / 100>
      <cfset agency_pct1 = ((percent - percent3) / 2) + percent3>
<!---step 5d   --->
      <cfif form.payperiod_amt gt 0>
            <cfset percent = form.payperiod_amt / 10000>
            dollar_percent = #percent#
      </cfif>
      
      <!---step 5a, b, c   --->
      <cfif other_amt eq 0>
            <cfif percent eq percent5 or percent gt percent5>
                  <cfset agency_match = (form.income * percent4) * form.period>
            <cfelseif percent eq percent3 or percent lt percent3>
                  <cfset agency_match = (form.income * percent) * form.period>
            <cfelse>              
                <cfset agency_pct1 = ((percent - percent3) / 2) + percent3>
                  <cfset agency_match = (agency_pct1 * form.income) * form.period>
            </cfif>
            <cfset tot_agency_match = form.tot_agency_match + agency_match>
      <cfelse>
            <cfset percent = ((uniform_amt / tot_income) * 100) / 100>
            <cfif percent eq percent5 or percent gt percent5>
                  <cfset agency_match = (form.income * percent4) * form.period>
            <cfelseif percent eq percent3 or percent lt percent3>
                  <cfset agency_match = (form.income * percent) * form.period>
            <cfelse>              
                <cfset agency_pct1 = ((percent - percent3) / 2) + percent3>
                  <cfset agency_match = (agency_pct1 * form.income) * form.period>
            </cfif>
            <cfset tot_agency_match = form.tot_agency_match + agency_match>
      </cfif>
</cfoutput>
<cfoutput>

<!---return to form program to add multiple entries   --->
<cfif isdefined("form.add")>
     <SCRIPT LANGUAGE='JavaScript'>
        location = ("pab_intro.cfm?tot_agency_match=#tot_agency_match#&tot_income=#tot_income#&systype=#form.systype#&income=#form.income#&tot_dollar=#tot_dollar#&tot_percent=#tot_percent#&payperiods=#payperiods#") ;
     </SCRIPT>
</cfif>



Thanks,
Rhonda
0
 
samtran0331Commented:
You can also load all the inputs into a session
CF sessions:
http://int.echex.net/cfdocs/Developing_ColdFusion_MX_Applications_with_CFML/sharedVars5.html
and
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?event=view&id=KC.tn_16563&extid=tn_16563&dialogID=45500883&iterationID=1&sessionID=483077d4479753576365&stateID=1+0+45526129&mode=simple

...think of your user's calculations as a "shopping cart"...each time they run the calc, an item gets added to the cart.
Using session, you can manipulate it a bit easier than using a hidden field with one long string....
hth
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now