http://www.perlmonks.org?node_id=1003518


in reply to Possible to refer to variable defined later in script?

I have had a similar design issue in the past - at that time, what I did was to create an empty <DIV> element at the top, then populate it later in the page using perl-generated javascript code that referenced the DIV.

update: Here is the Javascript function I called to update the DIV text:

function replaceText(sId, sText) { var el; if (document.getElementById && (el = document.getElementById(sId))) { while (el.hasChildNodes()) el.removeChild(el.lastChild); el.appendChild(document.createTextNode(sText)); } }
In my case, the ID belonged to a <td> element of a CGI generated table:
td({-id=>'SPECIALNAME_' . $g->Identifier},'N/A'), # The 'N/A' gets r +eplaced

             "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius