Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing additional information through an onclick/javascript function
    text
    copied!<p>Hi I'm using javascript/php/html and at the moment I am displaying information on "Cars" when I click more information it displays "further information" on the same cars and hides the cars tab (all this information is taken from a database). </p> <p>But right now i'm trying to get it to display this information but for each "car" to have its own "further information" so when I click it, it just shows that cars information beneath it alongside the "car". And when I click another car it hides the previous further information and displays the new one.</p> <p>Here is how I have done it, but it just displays the link, the link doesn't do anything...</p> <p>Javascript: </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function toggle_visibility(id) { var thelist = document.getElementsByClassName("alist"); for (var i = 0; i &lt; thelist.length; i++) { thelist[i].style.display = 'none'; } var e = document.getElementById(id); if(e.style.display == 'block') { e.style.display = 'none'; } else { e.style.display = 'block'; } } //]]&gt; &lt;/script&gt; &lt;/head&gt; </code></pre> <p>PHP:</p> <pre><code>&lt;body&gt; &lt;a href="#" onclick="toggle_visibility('list1');"&gt; &lt;p&gt;Car information&lt;/p&gt; &lt;/a&gt; &lt;div id="list1" class="alist" style="display:none;"&gt; &lt;?php $sql = "SELECT * from Car"; $result = mysql_query ($sql); while ($details = mysql_fetch_array ($result)) { $display = "&lt;p&gt;"; $display.= $details["carMake"] . "&amp;nbsp;"; $display.= $details["carModel"]; $display.="&lt;a href='#' &gt;More information&lt;/a&gt;"; $display.="&lt;/p&gt;"; echo ($display); } ?&gt; &lt;/div&gt; &lt;a href="#" onclick="toggle_visibility('list2');"&gt; &lt;p&gt;More information&lt;/p&gt; &lt;/a&gt; &lt;div id="list2" class="alist" style="display:none;"&gt; &lt;?php $sql = "SELECT * from Car"; $result = mysql_query ($sql); while ($details = mysql_fetch_array ($result)) { $display = "&lt;p&gt;"; $display.= $details["carMileage"]; $display.= $details["carColour"]; $display.= $details["carMOT"]; $display.= "&lt;/p&gt;"; echo ($display); } ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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