Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need help populating dynamically-created fields

New Here ,
Jan 31, 2008 Jan 31, 2008
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?
357
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2008 Jan 31, 2008
Won't it work if you simply re-run the query? Or does the action page not add more records?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2008 Jan 31, 2008
LATEST
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources