Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Because each div has the same ID. You need to create unique ID's for each DIV to show or hide ie. frDocViewer1, frDocViewer2 etc</p> <p>Use your $count variable to echo it's value onto the ID as it will increment by 1 for each iteration of the loop.</p> <pre><code>echo " &lt;image src='utube.gif' onclick='HideFrame()' /&gt; &lt;div id='frDocViewer_{$count}'&gt; $iframe &lt;/div&gt; "; </code></pre> <p>Then you just need to make sure that you have corresponding Javascript for each of those DIV's. I would send the id into the javascript function using your onclick tag.</p> <pre><code>for ($count=1; $count&lt;= $lastid ; $count++) { $iframe = mysql_query ("SELECT * FROM embed WHERE id=$count "); $iframe = mysql_fetch_assoc($iframe); $iframe = $iframe['url']; echo " &lt;image src='utube.gif' onclick='HideFrame({$count})' /&gt; &lt;div id='frDocViewer_{$count}' class='frDocViewer'&gt; $iframe &lt;/div&gt; "; } </code></pre> <p>And then have the javascript code as something like:</p> <pre><code>var old_element = null; function HideFrame(id) { var fr = document.getElementById("frDocViewer_" + id); if(fr != old_element) { fr.style.display = "block" if(old_element != null) old_element.style.display = "hide"; old_element = fr; } } </code></pre> <p>Then finally you need to change your CSS to make frDocViewer a class rather than a unique style. Notice above in the PHP echo string I added in the new class attribute to the DIV</p> <pre><code>&lt;style type="text/css"&gt; .frDocViewer { width:70%; height:50%; display:none; } &lt;/style&gt; </code></pre> <p>PS: This code might not actually compile, it's just a rough guide.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload