Ask a Question related to Coldfusion Database Access, Design and Development.
-
sage703 #1
Dynamic generation of list boxes based on user input
This topic is similar to my last topic, but is slightly different.
Again, I'm using session variables and a form wizard that takes the user
through a 12-step process (using 12 coldfusion pages, including NEXT and BACK
buttons), to allow the user to enter a new program into the database. Several
tables are updated during this process.
Now, let's say on step 4 of this form wizard the user is asked to put the
program into various classifications. Each classification will include a SERIES
of listboxes. First, the user has to be able to input *the number of
classifications they want the program to fit into*. Once they've typed that in
(or selected it using a list box), then they would be presented with another
coldfusion page that gives them 6 different list boxes they need to fill out
for EACH classification. Therefore, if they selected 3 classifications for the
program...they would get 3 sets of identical list box controls (each with the
same values in them).
What I need help with is 1) first of all determining how to dynamically
generate the multiple sets of list box controls based on the number of
classifications the user specified, and,
2.) Second, I need help determing how to set the values selected in those list
boxes to session variables. (Note: all the list box controls in this example
should only allow one selection at a time).
Once i have them as variables I think it should be a fairly simple process to
INSERT them into the appropriate table.
Thanks,
S./
sage703 Guest
-
Creating client-side dynamic dependent list boxes in ASP
I am trying to link two list boxes on a page using client side java. I am using Macromedia's Tech Note on this issue but still cannot get it to... -
Insert data into a form based on user input
You have a list menu field call company invoice number and 2 other fields called customer name and cust invoice. Is there a way to have the user... -
How do I get the input from a user web cotnrol and build the control based on that?
Hi, I'm building a user login control, which will accept a username and password in textboxes and a checkbox to keep logged in - pretty much your... -
Selecting data based on user input
Hi ! I have a table on my sql-server with date, value1, value2 How can I make a asp where the user can input date range, and the number of... -
Dynamic List based on form field data
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.500 / Virus Database: 298 -... -
mxstu #2
Re: Dynamic generation of list boxes based on user input
If the user selects (3) classifications, do you want to produce three
comma-delimited lists containing the selected values ..
Classification 1: 1,4,6,7,8,14
Classification 2: 22,4,6,7,16,2
Classification 3: 10,3,6,7,9,22
Or do you need to retrieve each of the (18) selections individually ?
Classification 1:
Selection 1 Value...
Selection 2 Value...
etc...
Classification 2:
Selection 1 Value...
Selection 2 Value...
mxstu Guest
-
sage703 #3
Re: Dynamic generation of list boxes based on user input
Let's pretend the user just wanted to do ONE classification. I imagine them
putting the value '1' into a form field on it's own page, maybe with a session
variable called SESSION.ProgWiz.NumClass, or some such thing. They press the
'next' button in the wizard SESSION.ProgWiz.NumClass variable is saved. This
next page should show them a number of select fields based on the number of
classifications they wish to make.
So, in this particular example, the user would have to make ONE selection from
each of SEVEN list boxes. One selection because I don't want multiple
selections. Seven list boxes because that's the number of columns in the table
that need to be filled for each classification of a program. So the user makes
a selection in each of those seven list boxes and presses the 'Next' button.
These selections are then saved as session variables to be used in INSERT
statements later on. Of course I could just make static session variables to
hold these values if the user was always just going to select one value from
each list box. HOWEVER, since the user might choose to make more than one
classification (up to about 5 let's say), it's not so easy to make static
session variables.
Now, if the user chooses to make THREE classifications then they would need
somehow to be presented with THREE SETS of seven listboxes, or 21 list boxes
total (3 list boxes in each set being identical in all legal respects). Each
set of seven would need to be stored as a GROUP (?) so that each set could be
entered into the table as one record.
Keep in mind that each record will have seven values. So essentially if the
user selects 3 classifications they will be wanting to make 3 separate entries
into this particular table, each entry needing to fill up the space of seven
columns, because that's how many are in the table.
One problem is that I am unsure how to save the values retrieved from these
selections. Since I don't know how many classifications the user is going to be
wanting to make when i write the script I can't hardwire any session variables.
I was thinking I might need to use a a level-2 array. For example 'ArrayName
[classification] [fieldname]' > but again, how would i get the fieldname as
this would also need to be dynamically created based on the number of
classifications set.
Am i clarifying this better mxstu? If not, please let me know how I can
clarify it further (perhaps with some code?).
S./
sage703 Guest
-
mxstu #4
Re: Dynamic generation of list boxes based on user input
Generating the lists is the easy part, but how you want to store the values
depends on what you need to do with them. A two-dimensional array would
probably work fine here.
First let me ask you this ...
- The reason why there are (7) columns in the table is because these are (7)
different properties? (i.e. The user will select (1) item from (7) *different*
lists of information, not (1) list repeated (7) times ) I ask because I'm
wondering whether you have the best table structure.
- Is there any code/text (e.g. CLASS123-ABC) associated with each
classification, or are you just tracking the number of classifications selected?
mxstu Guest
-
sage703 #5
Re: Dynamic generation of list boxes based on user input
:D I know the DB structure is not the best, but it's what i have to work with
(separation of powers or something).
To try to answer your question, the user will make a separate selection on
each of 7 columns (this process will be repeated however many times the user
specifies in the classification input field). Let's see if I can break down the
structure of the table from which they'll select data:
Program_Classification (table):
Field1: Program_Name
Field2:Cluster
Field3:AK_Cluster
Field4:Care_Type
Field5:Profession
Field6:Class
Field7:Ladder_Level
Field8:Field
All of the above fields will be represented individually (or so i was
thinking) as select lists from which distinct values of current data in those
lists could be selected. If the user wants to make one program classification
for the program they are adding to the DB they select ONE value from the
Cluster field, one value from the AK_Cluster field, one value from the
Care_Type field and so on.
IF they decide they want to classify the program in several categories, then I
imagine them being presented with 2 sets of the 7 select listboxes. Each set
would contain a list box for each of the fields listed above. Only in this
second case they would have two sets of the list boxes.
If they wrote in 3 classifications they would get 3 sets and so on. So, for
example, if they chose to make 3 classifications they would have to choose 3
different Cluster field values from 3 different select boxes. Moreover, they
would have to make 3 different AK_Cluster value selections (again, from 3
different select boxes). Each group of values would probably need to be stored
together somehow (like you said, perhaps in a 2-dimensional array) so the
program knew which Cluster field selection went with which AK_Cluster field
selection, Care_Type selection, Profession selection and so forth.
The reason being that for each classification the program will have ONE
cluster field value, ONE AK_cluster field value, ONE care_type field value, ONE
Profession field value and so on.
You also asked about classification code or whether I just need to know how
many classifications were selected. The program really only needs to know how
*many* were selected in order to make the number of list boxes the user will
need to select values from. Other than that I don't know what the number of
classifications would be used for (although perhaps as a looping variable of
some sort).
Am I making things more clear? :)
S./
sage703 Guest
-
sage703 #6
Re: Dynamic generation of list boxes based on user input
Hello again mxstu.
I've written out some preliminary code for the kind of thing I *think* might
work. Perhaps you can help me refine it.
<!--- declare index variable --->
<cfparam name="i" default=1>
<!--- declare arrays and number of classifications variables at top of
sessions page --->
<!--- other variables declared above these... --->
<cfset SESSION.ProgWiz.NumClass = "">
<cfset SESSION.ProgWiz.Cluster = ArrayNew(2)>
<cfset SESSION.ProgWiz.AK_Cluster = ArrayNew(2)>
<!--- other variables declared below these, including the other 5 arrays...
--->
<!--- determine if variables have already been filled in other pages --->
<!--- if so, pre-fill them with those values --->
<!--- other variables are pre-filled above these --->
<cfelseif IsDefined("Form.NumClass")>
<cfset SESSION.ProgWiz.NumClass = Form.NumClass>
<cfelseif IsDefined("Form.Cluster#i#")>
<cfset SESSION.ProgWiz.Cluster = Form.Cluster#i#>
<cfset SESSION.ProgWiz.AK_Cluster = Form.AK_Cluster#i#>
<!--- other variables pre-filled below these including the rest of the arrays
--->
<!--- on the classifications page of the new program wizard --->
<p>
<b>Number of classifications:</b> <br />
<cfinput name="NumClass" value="#SESSION.ProgWiz.NumClass#" size="5"
required="yes" message="You must enter a number.">
</p>
<!--- on the page after the classifications page--->
<!--- select data to fill select boxes --->
<cfquery name="cluster" datasource="#data_source#">
SELECT distinct Cluster
FROM Program_Classification
ORDER BY Cluster
</cfquery>
<cfquery name="akcluster" datasource="#data_source#">
SELECT distinct AK_Cluster
FROM AK_Cluster
ORDER BY AK_Cluster
</cfquery>
<!--- more queries would be here --->
<!--- first make sure NumClass variable is set by user --->
<cfif IsDefined("#SESSION.ProgWiz.NumClass#")>
<!--- loop through NumClass --->
<cfloop from="1" to="#SESSION.ProgWiz.NumClass#" index="i">
<!--- tell user what classification they are filling out first
--->
<p>
<b>Program Classification #index#:</b>
</p>
<!--- first select box pre-filled with data --->
<p>
Select a Cluster: <br />
<cfselect query="cluster" name="Cluster#i#"
value="#SESSION.ProgWiz.Cluster"/>
</p>
<!--- second select box pre-filled with data --->
<p>
Select an AK_Cluster: <br />
<cfselect name="AK_Cluster#i#" value="#SESSION.ProgWiz.AK_Cluster"/>
</p>
<!--- other select lists here --->
<!--- html horizontal rule to separate sets of list --->
<hr>
What do you think?
S./
sage703 Guest
-
mxstu #7
Re: Dynamic generation of list boxes based on user input
I know the DB structure is not the best, but it's what i have to work with
(separation of powers or something).
Well, that's a difficult situation, but IMO its a pay for it now or pay more
for it later situtation, as most likely you'll be the one dealing with these
issues down the road ;-) For example, if the database uses strings as foreign
keys (ex. "Program_Name"), and does not utilize some sort of
constraints/triggers to maintain integrity, then as soon as someone changes a
"Program_Name" in one table, some of your queries may break and will no longer
return the correct results. Personally, I prefer not to use strings as foreign
keys in most cases, even with constraints, but that's another issue.
I'll check out the code you posted.
mxstu Guest
-
mxstu #8
Re: Dynamic generation of list boxes based on user input
Here's a crude one page example of converting groups of lists to a
2-dimensional array. The field names and generic and it needs validation but it
should give you an idea of the concept.
<!--- step 1: select number of classifications --->
<form method="post">
Number of Classifications: <input type="text" name="numberOfClassifications"
size="2" value="3">
<input type="hidden" name="step2" value="yes">
<input type="submit">
</form>
<cfif IsDefined("form.numberOfClassifications")>
<!--- step 2: create test form with groups of lists --->
<cfif IsDefined("form.step2")>
<form method="post">
<cfoutput>
<cfloop from="1" to="#form.numberOfClassifications#" index="i">
<b>List group [#i#]:</b>
<!--- create 7 lists for current classification group --->
<cfloop from="1" to="7" index="j">
[#j#]
<select name="classification_#i#_#j#">
<option value="A #i##j#">A #i##j#</option>
<option value="B #i##j#">B #i##j#</option>
<option value="C #i##j#">C #i##j#</option>
</select>
</cfloop>
<br>
</cfloop>
<input type="hidden" name="numberOfClassifications"
value="#form.numberOfClassifications#">
</cfoutput>
<input type="hidden" name="step3" value="yes">
<input type="submit">
</form>
</cfif>
<!--- step 3: process list selections --->
<cfif IsDefined("form.step3")>
<cfset userSelections = ArrayNew(2)>
<cfloop from="1" to="#form.numberOfClassifications#" index="i">
<!--- retrieve values for each of 7 lists for this group --->
<cfloop from="1" to="7" index="j">
<cfset userSelections[i][j] = form["classification_"& i &"_"& j]>
</cfloop>
</cfloop>
<!--- display 2-Dim array --->
<cfdump var="#userSelections#">
</cfif>
</cfif>
mxstu Guest
-
sage703 #9
Re: Dynamic generation of list boxes based on user input
Hey thanks mxstu! I'm getting another related error however that I'm hoping you
can help with:
I dissected your code and modified it for my application (you'll notice I
removed the 2-dim array in favor of a 1-dim array). The problem now is that in
step 3 the CF Admin. is telling me:
Cannot convert #form.NumClass# to number.
Any idea why i might be getting this?
Here's the code as modified:
<!--- get number of classifications --->
<form method="post"
<p>
<b>Number of classifications for program: </b><br />
<cfinput type="text" name="NumClass" value="1" size="2">
<input type="hidden" name="step2" value="yes"
<input type="submit" value="Populate">
</form>
<!--- show all classifications --->
<!--- pre-select if user has chosen already --->
<cfif IsDefined("SESSION.ProgWiz.NumClass")>
<!--- step 2: create form with groups of lists --->
<cfif IsDefined("form.step2")>
<form method="post">
<cfloop from="1" to="#form.NumClass#" index="i">
<cfoutput>
<b>Program Classification Group [#i#]:</b>
</cfoutput>
<p>
<b>Select a Cluster:</b><br />
<cfselect name="cluster_#i#"
value="Cluster" query="cluster"/>
</p>
<p>
<b>Select a Field:</b> <br />
<cfselect name="field_#i#" value="Field" query="field"/>
</p>
<p>
<b>Select a Profession:</b> <br />
<cfselect name="profession_#i#"
value="Profession" query="profession"/>
</p>
<p>
<b>Select a Care Type:</b> <br />
<cfselect name="caretype_#i#" value="Care_Type" query="caretype"/>
</p>
<p>
<b>Select a Class:</b> <br />
<cfselect name="class_#i#" value="Class" query="class"/>
</p>
<p>
<b>Select a Ladder Level:</b> <br />
<cfselect name="ladderlevel_#i#" value="Ladder_Level"
query="ladderlevel"/>
</p>
<p>
<b>Select an AK Cluster:</b> <br />
<cfselect name="akcluster_#i#">
<cfoutput>
<cfloop list="#akcluster#" index="i">
<option value="#i#">#i#</option>
</cfloop>
</cfoutput>
</cfselect>
<hr />
</cfloop>
<br />
<input type="hidden" name="NumClass" value="#form.NumClass#">
<input type="hidden" name="step3" value="yes">
<input type="submit" value="Save Selections">
</form>
</cfif>
<!--- step 3: process list selections --->
<cfif IsDefined("form.step3")>
<cfloop from="1" to="#form.NumClass#" index="i">
<cfset SESSION.ProgWiz.Cluster = form["cluster_"& i]>
<cfset SESSION.ProgWiz.Field = form["field_"& i]>
<cfset SESSION.ProgWiz.Profession = form["profession_"& i]>
<cfset SESSION.ProgWiz.Care_Type = form["caretype_"& i]>
<cfset SESSION.ProgWiz.Class = form["class_"& i]>
<cfset SESSION.ProgWiz.Ladder_Level = form["ladderlevel_"& i]>
<cfset SESSION.ProgWiz.AK_Cluster = form["akcluster_"& i]>
</cfloop>
<!--- display 1-dim array --->
<cfdump var="#SESSION.ProgWiz.Cluster#">
</cfif>
</cfif>
</cfcase>
sage703 Guest
-
mxstu #10
Re: Dynamic generation of list boxes based on user input
At a guess, I would say you need to add a CFOUTPUT around the hidden form in
page 2
<cfoutput>
<input type="hidden" name="NumClass" value="#form.NumClass#">
<cfoutput>
Otherwise, the user entered number literally becomes the text
"#form.NumClass#" and not (3).
Make sure you validate the "NumClass" value, so that your form doesn't blow up
if the user enters "Two" instead of the number 2.
I'm not sure about the code where you are storing the selections.
<cfset SESSION.ProgWiz.Cluster = form["cluster_"& i]>
<cfset SESSION.ProgWiz.Field = form["field_"& i]>
I haven't been through the code completely, but I think you're just going to
end up with single values and not an array of multiple selections.
mxstu Guest
-
sage703 #11
Re: Dynamic generation of list boxes based on user input
Adding <cfoutput> made that part of the code work - thanks! : )
I've still got a few bugs to work out, such as my 'next' and 'back' buttons no
longer working on this particular step in the wizard; and I'll have to figure
out how to loop through my array(s) in order to enter the data sequentially
(the first value from the first array goes with the first value of the second
array and so on) into the database in my data processing page. These problems
don't sound overly complicated, but then again, I haven't started working on
them either.
Have a nice weekend. I'm sure if I have more problems with my code on Monday -
when i start working on this again - I'll be posting!
S./
sage703 Guest



Reply With Quote

