{"id":8781,"date":"2014-08-01T05:03:19","date_gmt":"2014-07-31T19:03:19","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=8781"},"modified":"2018-10-28T07:48:20","modified_gmt":"2018-10-27T21:48:20","slug":"static-html-javascript-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/static-html-javascript-primer-tutorial\/","title":{"rendered":"Static HTML Javascript Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/\"><img decoding=\"async\" id='ishjpt' style=\"float:left;border: 15px solid pink;\" alt=\"Static HTML Javascript Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/StaticHTML_Javascript.jpg\" title=\"Static HTML Javascript Primer Tutorial\" onmouseover=\" document.getElementById('ishjpt').src = document.getElementById('ishjpt').src.replace('.jpg', '.PNG').replace('.png', '.jpg').replace('.PNG', '.png');     \"  \/><\/a><p class=\"wp-caption-text\">Static HTML Javascript Primer Tutorial<\/p><\/div>\n<p>Very simple static HTML that has not been readied for Javascript <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Document_Object_Model' title='DOM is Document Object Model talked about on Wikipedia here ... thanks'>DOM<\/a> manipulations can still be dynamically changed and worked with to turn your <i>&#8220;sow&#8217;s ear&#8221;<\/i> into your <i>&#8220;silk purse&#8221;<\/i> (even if the <a target=_blank href='https:\/\/www.google.com.au\/search?client=firefox-a&#038;hs=p20&#038;rls=org.mozilla:en-US:official&#038;channel=sb&#038;source=lnms&#038;tbm=isch&#038;sa=X&#038;ei=KpPZU5GwENGSuASCw4DQBw&#038;ved=0CAgQ_AUoAQ&#038;biw=1260&#038;bih=673&#038;q=%22sow%E2%80%99s%20ear%E2%80%9D%20%E2%80%9Csilk%20purse%22%20%22pigs%20flying%22#facrc=_&#038;imgdii=_&#038;imgrc=qaTbhaZvhqRT6M%253A%3BSGTFtgY7JaGvSM%3Bhttp%253A%252F%252Fwww.wolfestone.co.uk%252Fcontent%252Fuploads%252F2012%252F05%252FFlying_Pig.jpg%3Bhttp%253A%252F%252Fwww.wolfestone.co.uk%252Fblog%252Fgo-global-with-wolfestone-translation-pigs-might-fly-2%252F%3B305%3B283'>pigs are flying<\/a>?!).<\/p>\n<p>The only real requirement to be able to create a web page using Javascript DOM is a knowledge of which HTML element types go to make up the web page data, and the order in which those HTML elements are placed, maybe &#8230; perhaps you don&#8217;t even need to know this.   Once you know that, even if the web page data has no <i>id=<\/i> nor (input tag) <i>name=<\/i> specification, you can still use Javascript DOM&#8217;s <a target=_blank href='http:\/\/www.w3schools.com\/jsref\/met_document_getelementsbytagname.asp' title='Javascript getElementsByTagName() information from w3schools ... thanks'><i>getElementsByTagName()<\/i><\/a> method to create the Javascript DOM functionality you wish to place on top of simple static HTML you have inherited.  In the two phase operation, for static HTML with no <i>id=<\/i> first use a looping of <i>getElementsByTagName()<\/i> for known HTML element types and assign <i>id=<\/i>&#8216;s to elements that potentially need Javascript DOM attention, and for the rest of the time use Javascript DOM <a target=_blank href='http:\/\/www.w3schools.com\/jsref\/met_document_getelementbyid.asp' title='Javascript getElementById() information from w3schools ... thanks'><i>getElementById()<\/i><\/a> method to actually perform the dynamic functionality you wish to apply.<\/p>\n<p>We show today, also, the dynamic application of user interactivity via an HTML form tag with the use of the <i>GET<\/i> method (because we are only using HTML\/Javascript today (no PHP (which could handle the <i>POST<\/i> method)), the parameters of which we test for when the webpage loads, and the specifications for which we have full control over, hence the chance to use pieces of code like:<\/p>\n<p><codeblock>favcol = location.search.split(&#8220;favcol=&#8221;)[1] ? location.search.split(&#8220;favcol=&#8221;)[1].split(&#8220;&#038;&#8221;)[0] : &#8220;&#8221;;<\/codeblock><\/p>\n<p>So, today, we show the application of some code in an external Javascript file to show this being done to this simple starting static HTML <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.htmGETME\" title=\"addid.htm\">addid.htm<\/a> to (very minute changes to HTML, but bigger changes regarding external Javascript) <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.htm_GETME\" title=\"addid.htm\">addid.html<\/a> where the external Javascript (which makes all the dynamics) is <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.js-GETME\" title=\"addid.js\">addid.js<\/a><\/p>\n<p>Here is a link to the HTML code change differences (minute) <a target=_blank title='mystore.html' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.html-GETME\">addid.html<\/a> and here is a link to the external Javascript code change differences (second) <a target=_blank title='mystore.html' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.js-GETME\">addid.js<\/a> &#8230; chortle, chortle &#8230; get it &#8230; minute\/second &#8230; play on words &#8230; oh! &#8230; guess you had to be there &#8230; chortle, chortle.<\/p>\n<p>Here is a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.htm\" title=\"addid.htm\">live run<\/a> of the original static HTML, and here is a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/StaticHTML\/addid.html\" title=\"addid.html\">live run<\/a> of the Javascript DOM dynamically altered webpage.<\/p>\n<p>You may notice that a View->Page Source of the Javascript DOM enhanced web page shows no difference to the View->Page Source of the Static HTML.   There are two points to note about this:<\/p>\n<ul>\n<li>PHP <a target=_blank title='Static HTML Based PHP Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=8645'>enhanced<\/a> Static HTML will show all the bells and whistles with a View->Page Source scenario, because PHP <i>&#8220;plugs&#8221;<\/i> its &#8220;smarts&#8221; in at the server, while Javascript DOM works at the client level &#8230; have a look at <img onclick='window.open(\"http:\/\/infomotions.com\/musings\/waves\/clientservercomputing.html\",\"_blank\");' src='http:\/\/infomotions.com\/musings\/waves\/media\/client-server-illustration.gif' title='Thanks to http:\/\/infomotions.com\/musings\/waves\/clientservercomputing.html'><\/img><\/i>\n<li>Javascript enhanced Static HTML may not show the bells and whistles with a View->Page Source scenario, but the use of  the <a target=_blank href='http:\/\/www.mozilla.org\/en-US\/firefox\/new\/' title='Firefox home page'>Firefox<\/a> web browser and a very useful add-on called <a target=_blank title='Firebug home page' href='https:\/\/getfirebug.com\/'>Firebug<\/a> which you may want more information about <a target=_blank title='Firebug tutorials at this blog' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Firebug'>here<\/a>, makes it spring to life<\/li>\n<\/ul>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#8781' onclick='var dv=document.getElementById(\"d8781\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8781' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Very simple static HTML that has not been readied for Javascript DOM manipulations can still be dynamically changed and worked with to turn your &#8220;sow&#8217;s ear&#8221; into your &#8220;silk purse&#8221; (even if the pigs are flying?!). The only real requirement &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/static-html-javascript-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[213,354,438,439,486,576,652,997,1195,1319],"class_list":["post-8781","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-clientserver","tag-dom","tag-firebug","tag-firefox","tag-getelementbyid","tag-html","tag-javascript","tag-programming","tag-statichtml","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8781"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=8781"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8781\/revisions"}],"predecessor-version":[{"id":41543,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8781\/revisions\/41543"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=8781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=8781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=8781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}