Max_Davis
asked on
Take variables and set new ones based on variable values
I have a form like this:
<input type="Text" name="OtherProject" required="No" size="1" maxlength="3" value="">
<CFLOOP from="100" to="750" step="50" index="taskID">
<input type="Text" name="task#taskID#_Other" required="No" size="1" maxlength="4" value="">
</CFLOOP>
As you can see the second form field is inside of a loop, so it generates an array of 14 fields.
So for example the first form would be passed as such:
form.OtherProject=400
And the second as such:
form.task100_Other=5
form.task450_Other=2.5
form.task500_Other=11
So what I need is for the recieving file to set variables where Other is replaced by the number passed by form.OtherProject:
form.task100_400=5
form.task450_400=2.5
form.task500_400=11
Notice how some of the second form fields are left blank in my example, it should be programmed so that is ok.
Thank you for your help.
<input type="Text" name="OtherProject" required="No" size="1" maxlength="3" value="">
<CFLOOP from="100" to="750" step="50" index="taskID">
<input type="Text" name="task#taskID#_Other" required="No" size="1" maxlength="4" value="">
</CFLOOP>
As you can see the second form field is inside of a loop, so it generates an array of 14 fields.
So for example the first form would be passed as such:
form.OtherProject=400
And the second as such:
form.task100_Other=5
form.task450_Other=2.5
form.task500_Other=11
So what I need is for the recieving file to set variables where Other is replaced by the number passed by form.OtherProject:
form.task100_400=5
form.task450_400=2.5
form.task500_400=11
Notice how some of the second form fields are left blank in my example, it should be programmed so that is ok.
Thank you for your help.
On the receiving page:
<CFLOOP from="100" to="750" step="50" index="taskID">
<CFIF IsDefined("FORM.task#taskI D#_Other") EQ True>
<CFSET "FORM.task#taskID#_#FORM.O therProjec t#" = Evaluate("FORM.task#taskID #_Other")>
</CFIF>
</CFLOOP>
<CFLOOP from="100" to="750" step="50" index="taskID">
<CFIF IsDefined("FORM.task#taskI
<CFSET "FORM.task#taskID#_#FORM.O
</CFIF>
</CFLOOP>
i think it would be easier if you didn't use _Other on your original form, then you could just append the OtherProject value rather than trying to replace part of a variable name
<!--- page1.cfm --->
<cfoutput>
<form name="frmData" action="page2.cfm" method="post">
Other Project<input type="Text" name="OtherProject" required="No" size="1" maxlength="3" value=""><br>
<cfloop from="100" to="750" step="50" index="taskID">
<input type="Text" name="task#taskID#" required="No" size="1" maxlength="4" value=""><br>
</cfloop>
<input type="submit">
</form>
</cfoutput>
<!--- page2.cfm --->
<cfloop from="100" to="750" step="50" index="taskID">
<cfif isDefined('form.task#taskI D#')>
<input type="Text" name="task#taskID#_#form.O therProjec t#" required="No" size="1" maxlength="4" value=""><br>
</cfif>
</cfloop>
<!--- page1.cfm --->
<cfoutput>
<form name="frmData" action="page2.cfm" method="post">
Other Project<input type="Text" name="OtherProject" required="No" size="1" maxlength="3" value=""><br>
<cfloop from="100" to="750" step="50" index="taskID">
<input type="Text" name="task#taskID#" required="No" size="1" maxlength="4" value=""><br>
</cfloop>
<input type="submit">
</form>
</cfoutput>
<!--- page2.cfm --->
<cfloop from="100" to="750" step="50" index="taskID">
<cfif isDefined('form.task#taskI
<input type="Text" name="task#taskID#_#form.O
</cfif>
</cfloop>
if i understand u correctly - this shld help
run a loop on the submitted page as :
<CFLOOP FROM="100" TO="750" STEP="50" INDEX="taskID">
<CFIF ISDEFINED('TASK#TASKID#_OT HER') AND LEN(TRIM(EVALUATE('TASK#TA SKID#_OTHE R')))>
#task#taskID#_Other# = #evaluate('task#taskID#_Ot her')#<BR>
</CFIF>
</CFLOOP>
& see what output u get [it will pring only those form fields that u have NOT left blank]
let me know ...
K'Rgds
Anand
run a loop on the submitted page as :
<CFLOOP FROM="100" TO="750" STEP="50" INDEX="taskID">
<CFIF ISDEFINED('TASK#TASKID#_OT
#task#taskID#_Other# = #evaluate('task#taskID#_Ot
</CFIF>
</CFLOOP>
& see what output u get [it will pring only those form fields that u have NOT left blank]
let me know ...
K'Rgds
Anand
I think you want to use dynamic variables. When setting dynamic variables it's easy.
Ie
<cfset Test = "Hello">
<cfset "More#Test#" = "There">
<cfoutput>#MoreHello#</cfo utput>
To check for existance or value of a dynamic variable, you need to use IsDefined & evaluate.
Ie
<cfif IsDefined("More#Test#")>
The variable MoreHello is defined.
</cfif>
<cfif Evaluate("More#Test#") eq "There">
Yes we can do logical comparrisons!
</cfif>
Ie
<cfset Test = "Hello">
<cfset "More#Test#" = "There">
<cfoutput>#MoreHello#</cfo
To check for existance or value of a dynamic variable, you need to use IsDefined & evaluate.
Ie
<cfif IsDefined("More#Test#")>
The variable MoreHello is defined.
</cfif>
<cfif Evaluate("More#Test#") eq "There">
Yes we can do logical comparrisons!
</cfif>
Hi,
if I understand you correctly, you want to set the new variables only if the "_other" vars are not empty? The following code will do that:
<cfloop collection="#form#" item="field">
<cfif right(field, 6) EQ "_Other">
<cfif len(trim(form[field]))>
<cfset form[replaceNoCase(field, "other", taskID, "ALL")] = form[field]>
</cfif>
</cfif>
</cfloop>
if I understand you correctly, you want to set the new variables only if the "_other" vars are not empty? The following code will do that:
<cfloop collection="#form#" item="field">
<cfif right(field, 6) EQ "_Other">
<cfif len(trim(form[field]))>
<cfset form[replaceNoCase(field, "other", taskID, "ALL")] = form[field]>
</cfif>
</cfif>
</cfloop>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
weird !
After the form is submited you want to then make a new form with the names task450_400? Or you want to be able to access form.task100_400?
Maybe any code you have available would help us understand it?