javascript multiple onload functions
Posted: Thu Dec 10, 2009 2:45 pm
I'm trying to pass the same function twice in the body onload tag with different variables like this:
<body onload="display('name1'); display('name2');">
where display(param) looks like
and the file has divs:
<div id="name1"></div>
<div id="name2"></div>
so that the phrase passed through display() gets put in a div of the same id as the param.
It works fine with just one funtion i.e. <body onload="display('name1');"> but when I use php to dynamically add more display() functions to the onload and divs to the page I get a bunch of crap. Sometimes the name2 gets put in <div id="name1"></div>. Any suggestions?
<body onload="display('name1'); display('name2');">
where display(param) looks like
Code: Select all
function display(param) {
document.getElementById(param).innerHTML = param;
}
<div id="name1"></div>
<div id="name2"></div>
so that the phrase passed through display() gets put in a div of the same id as the param.
It works fine with just one funtion i.e. <body onload="display('name1');"> but when I use php to dynamically add more display() functions to the onload and divs to the page I get a bunch of crap. Sometimes the name2 gets put in <div id="name1"></div>. Any suggestions?