title: Add HTML elements if a particular file exists on the server
body: <p>I'm trying to create an HTML page that will change depending on what is in the current directory. There is an image box, and buttons that change the image. But because this page is identical throughout different pages, is there any way to add or remove these buttons depending on how many images are in the same directory?</p>
  
  <p>The idea is that the site will then be expandable with minimal effort for changing each page, such that other users can do it. In the file below, it is the changePage button that needs to be removed.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
      &lt;head id="head"&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
          &lt;title&gt;
              Maths Study and Revision
          &lt;/title&gt;
          &lt;link href="./styles.css" rel="stylesheet" type="text/css"&gt;
          &lt;script type="text/javascript"&gt;
          function changePage(page) {
              var img = document.getElementById("image");
              img.src="./pages/page_" + page + ".png";
              return false;
          }
  
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body background="/img/image.jpg"&gt;
      &lt;div id="container"&gt;
          &lt;div id="header"&gt;
              &lt;h1 style="border-style:solid;border-color:White;border-width:1px;"&gt;
                  Maths Study and Revision
              &lt;/h1&gt;
          &lt;/div&gt;
          &lt;div id="menuwrapper"&gt;
              &lt;ul&gt;
                  &lt;li&gt;
                      &lt;a href="#"&gt;Higher Tier&lt;/a&gt;
                      &lt;ul&gt;
                          &lt;li&gt;
                              &lt;a href="#"&gt;Calculator Paper&lt;/a&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j13/hc/index.html"&gt;June 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/m13/hc/index.html"&gt;March 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/n12/hc/index.html"&gt;November 2012&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j12/hc/index.html"&gt;June 2012&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/li&gt;
                          &lt;li&gt;
                              &lt;a href="#"&gt;Non-Calculator Paper&lt;/a&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j13/hn/index.html"&gt;June 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/m13/hn/index.html"&gt;March 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/n12/hn/index.html"&gt;November 2012&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j12/hn/index.html"&gt;June 2012&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                      &lt;a href="#"&gt;Foundation Tier&lt;/a&gt;
                      &lt;ul&gt;
                          &lt;li&gt;
                              &lt;a href="#"&gt;Calculator Paper&lt;/a&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j13/fc/index.html"&gt;June 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/m13/fc/index.html"&gt;March 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/n12/fc/index.html"&gt;November 2012&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j12/fc/index.html"&gt;June 2012&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/li&gt;
                          &lt;li&gt;
                              &lt;a href="#"&gt;Non-Calculator Paper&lt;/a&gt;
                              &lt;ul&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j13/fn/index.html"&gt;June 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/m13/fn/index.html"&gt;March 2013&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/n12/fn/index.html"&gt;November 2012&lt;/a&gt;
                                  &lt;/li&gt;
                                  &lt;li&gt;
                                      &lt;a href="/j12/fn/index.html"&gt;June 2012&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div id="intro"&gt;
              &lt;p style="float:left;margin-left:10px;margin-bottom:10px;"&gt;
                  &lt;object type='text/plain' data='./title.html' height="50px" width="800px"&gt;&lt;/object&gt;
              &lt;/p&gt;
          &lt;/div&gt;
          &lt;div id="exam"&gt;
              &lt;img src="./pages/page_1.png" id="image"&gt;
          &lt;/div&gt;
          &lt;div class="col1"&gt;
              &lt;button onclick="changePage('1')"&gt;Page 1&lt;/button&gt;                   
              &lt;button onclick="changePage('2')"&gt;Page 2&lt;/button&gt;
              &lt;button onclick="changePage('3')"&gt;Page 3&lt;/button&gt;
              &lt;button onclick="changePage('4')"&gt;Page 4&lt;/button&gt;
              &lt;button onclick="changePage('5')"&gt;Page 5&lt;/button&gt;
              &lt;button onclick="changePage('6')"&gt;Page 6&lt;/button&gt;
              &lt;button onclick="changePage('7')"&gt;Page 7&lt;/button&gt;
              &lt;button onclick="changePage('8')"&gt;Page 8&lt;/button&gt;
              &lt;button onclick="changePage('9')"&gt;Page 9&lt;/button&gt;
              &lt;button onclick="changePage('10')"&gt;Page 10&lt;/button&gt;
              &lt;button onclick="changePage('11')"&gt;Page 11&lt;/button&gt;         
              &lt;button onclick="changePage('12')"&gt;Page 12&lt;/button&gt;
              &lt;button onclick="changePage('13')"&gt;Page 13&lt;/button&gt;
              &lt;button onclick="changePage('14')"&gt;Page 14&lt;/button&gt;
              &lt;button onclick="changePage('15')"&gt;Page 15&lt;/button&gt;
              &lt;button onclick="changePage('16')"&gt;Page 16&lt;/button&gt;
              &lt;button onclick="changePage('17')"&gt;Page 17&lt;/button&gt;
              &lt;button onclick="changePage('18')"&gt;Page 18&lt;/button&gt;
              &lt;button onclick="changePage('19')"&gt;Page 19&lt;/button&gt;
              &lt;button onclick="changePage('20')"&gt;Page 20&lt;/button&gt;
              &lt;button onclick="changePage('21')"&gt;Page 21&lt;/button&gt;
              &lt;button onclick="changePage('22')"&gt;Page 22&lt;/button&gt;
              &lt;button onclick="changePage('23')"&gt;Page 23&lt;/button&gt;
              &lt;button onclick="changePage('24')"&gt;Page 24&lt;/button&gt;
          &lt;/div&gt;
          &lt;div id="footer"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Any help will be greatly appreciated! </p>