Return to Snippet

Revision: 24026
at February 18, 2010 21:31 by hrbrmstr


Initial Code
<img src="" id="graphs"/><br/>
<script>
    d = new Date();

    year = d.getFullYear();
    day = d.getDate();
    month = d.getMonth() + 1;

    DAY = day.toString() ;
    MONTH = month.toString();
    YEAR = year.toString(); 

    document.getElementById("graphs").src = "http://www.wunderground.com/cgi-bin/wxStationG
    raphAll?day=" + DAY + "&year=" + YEAR + "&month=" + MONTH + "&ID=KMEBERWI7&type=3&width=500
    &showtemp=1&showpressure=1&showwind=1&showwinddir=1&showrain=1" ;
</script>

Initial URL

                                

Initial Description
If you need to have an <img> tag be dynamic (in this case, I wanted to reference my weather station graphs from Weather Underground and ensure I had "today's" graph without updating the HTML by hand), then this is the way to do it. I made it more verbose just for illustration. You can reduce the code-size dramatically if that's important to you.

Initial Title
Dynamic IMG (tag) using javascript

Initial Tags

                                

Initial Language
JavaScript