title: How do I trigger a Javascript function AFTER the page loads?
body: <p>** EDIT **</p>
  
  <p>I'm afraid I wasn't in the right direction - the problem isn't what I asked about.
  the Javascript works as it should, it's the PHP that doesn't show what I want it to
  on the first "run" - and I'm stil not sure why.
  Sorry for somewhat wasting your time...</p>
  
  <p>**</p>
  
  <p>I have a form that might or might not already contain data in its fields.
  If a user reaches the form and he already has some data in the system,
  his ID number, for instance, will appear in the ID field - and a JavaScript function running
  onLoad will disable the input field and change its style:</p>
  
  <pre><code>&lt;body onload="runFunction()"&gt;
  </code></pre>
  
  <p>the problem is that it seems to run before the PHP does its part,
  and only if I refresh the page, the JS function does everything I want it to
  (it disables and styles some other form fields that depend on a PHP condition).</p>
  
  <p>Is there a way to have this JS function run AFTER the page was rendered?
  I tried running this before closing the page:</p>
  
  <pre><code>&lt;body&gt;
  ...
  ...
  &lt;script&gt;
  runFunction();
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>but to no avail.</p>
  
  <p>any ideas?
  Thanks!</p>
  
  <p>some of the relevant PHP code: [I removed id attributes to make reading easier]</p>
  
  <pre><code>&lt;?php if ($h_phone != '' &amp;&amp; $h_phone_pre != '') {  
  echo "&lt;td class=\"input\"&gt;&lt;input type=\"text\" id=\"new_user_home_tel\" value=\"$h_phone\" size=\"8\" maxlength=\"7\" disabled=\"disabled\" /&gt; -  
  &lt;select id=\"new_user_home_tel_pre\" disabled=\"disabled\"&gt;  
    &lt;option value=\"$h_phone_pre\" selected=\"selected\"&gt;&lt;/option&gt;";
  
       } else {
  
  echo '&lt;td class="input"&gt;&lt;input type="text" id="new_user_home_tel" size="8" maxlength="7" /&gt; -  
   &lt;select id="new_user_home_tel_pre"&gt;  
     &lt;option value=" " selected="selected"&gt;&lt;/option&gt;';
      }?&gt;  &lt;option value="02"&gt;02&lt;/option&gt;
       &lt;option value="03"&gt;03&lt;/option&gt;
       &lt;option value="04"&gt;04&lt;/option&gt;
       &lt;option value="08"&gt;08&lt;/option&gt;
       &lt;option value="09"&gt;09&lt;/option&gt;
  &lt;/select&gt; 
  &lt;/td&gt;   
  </code></pre>
  
  <p>the Javascript code just changes the style if the field isn't empty and that works,
  but the PHP works only after a refresh.</p>