Document processing timing

I am building a form element by element based on user responses. I have an action page that is called after a certain response occurs .

the action page has an invoke of a cfc that reads a database of form elements and returns the results to the action page where they are output

Below the output of the form elements I have some javascript which will pre-populate some of the values of the newly added form elements.

However, it seems my Javascript always executes before the output of the form elements . this means I can not update the values of the elements because they do not exist yet. If I pause my Javascript the elements do not get drawn until I allow it to continue. JS is jumping in first.

Is there a method to make JS not execute until the from elements are drawn?
Top to bottom placement does not seem to matter.

<cfinvoke> go get the form elements
<cfloop> output the elements
<javascript> look up hidden form elements and populate the new form elements.

Thanks, i ended up using a confirm to notify the user something was about to happen to make their life easier, then delayed 2 seconds after the response using setTimeout. That gave CF what it needed to put the focus back on the form and draw the elements.

Just using the dom ready event was not working. It needed the actual break in processing. Still not sure I understand why.

You can use some kind of on dom ready event handler

or if you are using a JS library like mootools or jquery they have events which work for all browsers