Editing content of a webpage using either HTML or Script

=Introduction=
Essentially, HyperText Mark-up Language is for describing the content of a web page. The elements available in the language can identify the type of content (e.g. anchors, headings, sections, articles, asides, code, audio, button, caption, table, form, input, navigation, images, video and other media).
In some circumstances, the page needs to be dynamic, i.e. we need to be able to change part of the content. This article shows two ways of changing Cumulus derived content. Elsewhere on this Wiki, there are 3rd party web applications for displaying a year's observations in a calendar summary format, for frequently updated 'now' reporting, and for displaying weather graphically. Other dynamic pages such as those processing forms are outside the scope of this article.
If a web page change simply involves inserting a different object (e.g. an embedded web page, a text file, or an image), and that object is available, then HTML provides a mechanism for changing the content without using a script (Pure HTML example below).
For more flexibility in changing the content of a HTML page, there can be a call to a JavaScript code (Script example below) and that can do the same as pure HTML and more advanced manipulation. Although a particular person may choose not to enable it, JavaScript is available in most modern browsers across most hardware platforms (including smart phones). The browser will interpret the instuction in the script normally after it has loaded the initial direct HTML content.
Finally, the server that hosts a web page may offer a language that allows a script to be followed that results in a set of instructions being followed to generate some HTML code that is then sent to the user's browser. One example is PHP and again there are PHP using routines elsewhere in this Wiki.
Category:WebTipsSfws 17:02, 28 November 2012 (UTC)
===Pure HTML example===
 <!-- Large Image Position -->
	<iframe src="images/tempm.png" name="graphs" title="Weather Graphs" width="900" height="400">
	Your browser settings prohibit the 'iframe' element<img src="images/tempm.png" id="graphs"
 title="Weather Graph" alt="Monthly temperature trend graph" width="750" height="300"></iframe>
	<!-- IMAGES THUMBNAILS -->
	
		LAST MONTHSelect from graphs
 LAST <#graphperiod> HOURS 
		
			<a target="graphs"
 href="images/tempm.png"><img src="images/tempmsm.png" alt="Temp Min/Max Graph Thumbnail"/></a>
			These graphs present:temperature, pressure,
 rainfall, andwind speed trends
 for either the last <#graphperiod> hours or the last month (as shown on X axis).
Click on a thumbnail to show related large graph. 
			<a target="graphs"
 href="images/temp.png"><img src="images/tempsm.png" alt="Temperature Graph Thumbnail"/></a>
			<a target="graphs"
 href="images/hum.png"><img src="images/humsm.png" alt="Humidity Graph Thumbnail"/></a>
		
			<a target="graphs"
 href="images/raind.png"><img src="images/raindsm.png" alt="Daily Rain Graph Thumbnail"/></a>
<!-- text spans this cell -->
			<a target="graphs"
 href="images/rain.png"><img src="images/rainsm.png" alt="Rain Graph Thumbnail"/></a>
			<a target="graphs"
 href="images/raint.png"><img src="images/raintsm.png" alt="Today's Rainfall Graph Thumbnail"/></a>
		
			<img src="static_images/cumuluslogo.gif"
 title="logo for cumulus software" alt="Picture of a clumulus cloud with the words 'powered by cumulus'">
Graphsuploaded<#shortdayname> <#update>
			<a target="graphs"
 href="images/press.png"><img src="images/presssm.png" alt="Pressure Graph Thumbnail"/></a>
			<a target="graphs"
 href="images/wind.png"><img src="images/windsm.png" alt="Wind Graph Thumbnail"/></a>
			<a target="graphs"
 href="images/windd.png"><img src="images/winddsm.png" alt="Wind Direction Thumbnail"/></a>
		
This extract from HTML code for 'trendsT.htm' displays a large graph in the HTML element 'iframe' and then displays a number of small thumbnails generated by Cumulus. These are grouped according to the time period they cover. The 'a' HTML element round each of the small graphs means that clicking that image causes its larger version to be displayed in the iframe.
If you want to copy this code, note the 'target' attribute in the 'a' (anchor) element refers to the 'name' attribute in the 'iframe' element.
===Script Example===
<script type="text/javascript">
function changeImage(im) {document.images["graphs"].src = im + "?" + new Date().getTime();}
</script>
NOTE: In this version, a query string is used containing the time. A query string is something that starts with a question mark and follows a Universal Resource Locator (URL). The URL tells the browser where to find the (image) file it is being asked to load. The query string, in this case, tells the browser to load a fresh copy of the (image) file from its source because it will not match the query string on the file contained in a browser cache (if the browser options/preferences are set to allow cache copies to be used when the same file is requested again).
 <img src="images/wind.png" name="graphs" id="graphs" title="Weather Graphs" alt="Weather Graphs"/>
 Click on a thumbnail to show a large graph in the panel above. 
 <a onclick='changeImage("images/wind.png")'><img src="images/windsm.png"
 alt="Wind Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/temp.png")'><img src="images/tempsm.png"
 alt="Temperature Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/intemp.png")'><img src="images/intempsm.png"
 alt="Inside Temperature Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/press.png")'><img src="images/presssm.png"
 alt="Pressure Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/rain.png")'><img src="images/rainsm.png"
 alt="Rain Graph Thumbnail" width="150" height="100" border="0" /></a>
 
 <a onclick='changeImage("images/windd.png")'><img src="images/winddsm.png"
 alt="Wind Direction Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/tempm.png")'><img src="images/tempmsm.png"
 alt="Temp Min/Max Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/hum.png")'><img src="images/humsm.png"
 alt="Humidity Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/raint.png")'><img src="images/raintsm.png"
 alt="Today's Rainfall Graph Thumbnail" width="150" height="100" border="0" /></a>
 <a onclick='changeImage("images/raind.png")'><img src="images/raindsm.png"
 alt="Daily Rain Graph Thumbnail" width="150" height="100" border="0" /></a>
Page updated <#update>powered by <a href="http://sandaysoft.com/products/cumulus" target="_blank">Cumulus</a> v<#version> (<#build>)
This is the code supplied with Cumulus (and stored in web/originals directory) as at 5 July 2011. This extract from HTML code for 'trendsT.htm' displays a large graph in the HTML element 'p' (paragraph) and then displays a number of small thumbnails generated by Cumulus. It only works if JavaScript is enabled so the 'changeImage' function in the first pre-formatted area above is called by the 'onclick' argument in the second pre-formatted area.
= The next article to read …… =
Learn how to use a PHP script to generate HTML web pages. See PHP Hypertext Preprocessor.