Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use javascript/other method in order to print the date in a format, when requesting an image generated by a php script?
    text
    copied!<p>I am creating a site using bootstrap to give weather updates at the beach. <a href="http://www.newbrightonweatherstation.co.uk" rel="nofollow">MY SITE</a></p> <p>The following php script requests the correct image.</p> <pre><code>http://www.ntslf.org/files/php/pltdata_tgi.php?port=Liverpool&amp;span=4&amp;from=20130821 </code></pre> <p>the last set of numbers is the date backwards.</p> <p>Basically I want this image to update in the page and be the correct date. I tried using javascript but i couldn't get it to work</p> <pre><code>var var d = new Date(); var n = d.getDate(); </code></pre> <p>here is the source code for the website:</p> <pre><code>&lt;div class="col-lg-6"&gt; &lt;h3&gt;Tides&lt;/h3&gt; &lt;p&gt;Tides over the next 2 days&lt;/p&gt; &lt;img src="http://www.ntslf.org/files/php/pltdata_tgi.php?port=Liverpool&amp;span=4&amp;from=20130821" class="img-responsive" alt="Responsive image"&gt; &lt;/a&gt; &lt;/div&gt; </code></pre> <p>I can't work out how I would use javascript to change the img src to the correct date</p> <p>EDIT I now have and i'm still unable to make it work</p> <pre><code>&lt;div class="col-lg-6"&gt; &lt;h3&gt;Tides&lt;/h3&gt; &lt;p&gt;Tides over the next 2 days&lt;/p&gt; &lt;img src="http://www.ntslf.org/files/php/pltdata_tgi.php?port=Liverpool&amp;span=4&amp;from=20130821" class="img-responsive" alt="Responsive image"&gt; &lt;script&gt; var d = new Date(); var date = d.getFullYear() + '' + (d.getMonth()+1) + '' + d.getDate(); var image = document.getElementsByClass("img-responsive")[0]; image.src = 'http://www.ntslf.org/files/php/pltdata_tgi.php?port=Liverpool&amp;span=4&amp;from='+date; &lt;/script&gt; &lt;/a&gt; &lt;/div&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