title: How do I update an iframe from another iframe?
body: <p>I have an iframe with LOGIN and REGISTER buttons, the login button opens the login page in another iframe, and after submitting the login data the second iframe is refreshed.</p>
  
  <p>However, I would like to be able to also update the first iframe to change my LOGIN button to my LOGOUT button.</p>
  
  <p>$_SESSION['userlevel'] does have a value, and my loginmenu.php works fine to reflect the correct button when the whole page is refreshed with F5</p>
  
  <p>here is part of my index page which loads the code for my LOGIN and REGISTER buttons ...</p>
  
  <pre><code>   &lt;div class="login"&gt;
      &lt;iframe class="iframemain" name="iframe-login" id="loginmenu" src="loginmenu.php"&gt;&lt;/iframe&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p>here is my loginmenu.php ...</p>
  
  <pre><code>&lt;?php session_start();?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
  &lt;link rel="stylesheet" href="0000001.css" type="text/css" /&gt;
  &lt;title&gt; &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body class="login"&gt;
  &lt;?php
  $userlevel=$_SESSION['userlevel'];
  
  if ($userlevel=="") 
  {
   ?&gt;&lt;a href="login.php" target="iframemain"&gt;&lt;img id="loginImg" src="gfx/btn.menulogin.png"/&gt;&lt;/a&gt;&lt;img src="gfx/spacer.png" width="2px"/&gt;&lt;a href="register.php" target="iframe-body"&gt;&lt;img src="gfx/btn.menuregister.png"/&gt;&lt;/a&gt;&lt;?php
  }
  
  if ($userlevel&lt;&gt;"") 
  {
   ?&gt;&lt;a href="logout.php" target="iframemain"&gt;&lt;img src="gfx/btn.menulogout.png"/&gt;&lt;/a&gt;&lt;img src="gfx/spacer.png" width="2px"/&gt;&lt;a href="register.php" target="iframe-body"&gt;&lt;img src="gfx/btn.menuregister.png"/&gt;&lt;/a&gt;&lt;?php
  }
  
  ?&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>after validating the username and password ($form is actually "valid") ... here is my failing attempt to update my loginmenu.php ...</p>
  
  <pre><code>&lt;?php
  
  (validing code here)
  
  if($form=="valid")
   {
    ?&gt;
    &lt;script&gt;
    element=document.getElementById('loginmenu')
    element.src="loginmenu.php";
    &lt;/script&gt;
    &lt;?php
   }
  
  (other php functions here)
  
  ?&gt;
  </code></pre>
  
  <p>i have also tried this to see if the image will change, but it also fails</p>
  
  <pre><code>if($form=="valid")
   {
    ?&gt;
    &lt;script&gt;
    element=document.getElementById('loginImg')
    element.src="gfx/btn.menulogout.png";
    &lt;/script&gt;
    &lt;?php
   }
  </code></pre>