Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Possible to refer to variable defined later in script?

by NetWallah (Canon)
on Nov 12, 2012 at 22:55 UTC ( #1003518=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003518]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2018-05-21 18:00 GMT
Find Nodes?
    Voting Booth?