0
Need help populating dynamically-created fields
New Here
,
/t5/coldfusion-discussions/need-help-populating-dynamically-created-fields/td-p/914964
Jan 31, 2008
Jan 31, 2008
Copy link to clipboard
Copied
I have a form which uses Javascript to create table rows on
the fly so as to add items to a list dynamically. The table
consists of two fields -- an ID and let's call the other one
Attribute A. The user clicks "Add another one" and another row of
data entry fields pops up. My action page works fine to get the
value of these rows using the evaluate() function (I always
wondered what that did), but I want it to go back to the calling
page, have the calling page create the correct number of rows, and
populate them with the changed or inserted data that was just saved
-- the same way that an ordinary action page might save data and
then return you to the calling page.
The first row of this table is created through HTML and only additional rows are created dynamically.
I have it all working up to and including the creation of the correct number of fields as an "onload=(loadTheData)" in the <body> tag, but how the heck and where do I populate them with the data returned from the query?
Below is the Javascript and how it's called. I changed some variable names to protect the innocent, but that's basically how it works. So the Javascript is creating the fields -- one for each record returned by the query -- but how can I assign the record values in turn? Do I need WDDX? If so, how would that be written?
The first row of this table is created through HTML and only additional rows are created dynamically.
I have it all working up to and including the creation of the correct number of fields as an "onload=(loadTheData)" in the <body> tag, but how the heck and where do I populate them with the data returned from the query?
Below is the Javascript and how it's called. I changed some variable names to protect the innocent, but that's basically how it works. So the Javascript is creating the fields -- one for each record returned by the query -- but how can I assign the record values in turn? Do I need WDDX? If so, how would that be written?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/need-help-populating-dynamically-created-fields/m-p/914965#M84104
Jan 31, 2008
Jan 31, 2008
Copy link to clipboard
Copied
Won't it work if you simply re-run the query? Or does the
action page not add more records?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/need-help-populating-dynamically-created-fields/m-p/914966#M84105
Jan 31, 2008
Jan 31, 2008
Copy link to clipboard
Copied
If you are going to use JavaScript to dynamically create the
list, then
look into the <cfwddx...> tag that is very useful for translating
ColdFusion data structures into JavaScript data structures. You can
then use the JavaScript data to populate your table.
But I would think it would be simplier to use the ColdFusion data to
build the default table with existing data. Instead of just creating
one row with ColdFusion create rows for the existing data then just use
the JavaScript to add more rows on the client, just as you are doing now.
P.S. evaluate() is usually an awkward choice to access dynamical form
variables. I presume you are using something like
<cfset something = evaluate("form.aField_#aVar#")>
This can be easier with the use of array notation.
<cfset something = form['aField_' & aVar]>
OR
<cfset something = form['aField_#aVar#']>
To each his own, but knowing array notation is a very powerful technique.
look into the <cfwddx...> tag that is very useful for translating
ColdFusion data structures into JavaScript data structures. You can
then use the JavaScript data to populate your table.
But I would think it would be simplier to use the ColdFusion data to
build the default table with existing data. Instead of just creating
one row with ColdFusion create rows for the existing data then just use
the JavaScript to add more rows on the client, just as you are doing now.
P.S. evaluate() is usually an awkward choice to access dynamical form
variables. I presume you are using something like
<cfset something = evaluate("form.aField_#aVar#")>
This can be easier with the use of array notation.
<cfset something = form['aField_' & aVar]>
OR
<cfset something = form['aField_#aVar#']>
To each his own, but knowing array notation is a very powerful technique.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

