{"id":5683,"date":"2013-12-22T05:09:32","date_gmt":"2013-12-21T18:09:32","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5683"},"modified":"2013-12-22T05:09:32","modified_gmt":"2013-12-21T18:09:32","slug":"ajax-auto-completion-followup-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/ajax-auto-completion-followup-tutorial\/","title":{"rendered":"Ajax Auto-completion FollowUp Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/auto_language_complete.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Ajax Preview Window Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')\" id='aacpti'  onmouseover=\"var xqw=this.src; if (xqw.indexOf('1.png') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Language_Completion_2.png'; } else if (xqw.indexOf('2.png') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Language_Completion.png'; } else { this.src = 'http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Language_Completion_1.png'; }\"   src=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Language_Completion.png\" title=\"Ajax Auto-completion FollowUp Tutorial\" \/><\/a><p class=\"wp-caption-text\">Ajax Auto-completion FollowUp Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Ajax techniques make your web pages very dynamic and useful, and there will be fewer changes of webpage required when using Ajax, because information derived from a data source (maybe a feed, maybe a database read, maybe a local source of data (as for this tutorial&#8217;s <a target=_blank title='countries_attributed.xml' href='http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/countries_attributed.xml_GETME'>countries_attributed.xml<\/a> &#8230; today, we use attributes, as distinct from yesterday&#8217;s tutorial &#8230; in source code note use of <a target=_blank title='XML DOM getAttribute method' href='http:\/\/www.w3schools.com\/dom\/met_element_getattribute.asp'>getAttribute()<\/a> method &#8230; thanks to <a target=_blank title='great help' href='http:\/\/trac.reddes.bvsalud.org\/projects\/scielo-submission\/browser\/branches\/ojs-2.3.3-1\/lib\/pkp\/locale\/en_US\/countries.xml'>link<\/a> and <a target=_blank title='languages.xml' href='http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/languages.xml_GETME'>languages.xml<\/a> &#8230; in source code note use of <a target=_blank title='XML DOM getAttribute method' href='http:\/\/www.w3schools.com\/dom\/met_element_getattribute.asp'>getAttribute()<\/a> method &#8230; thanks to <a target=_blank title='Google Translate derived XML language code lookup' href='http:\/\/translate.google.com'>link<\/a> &#8230; (by the way, with this last derived XML, it would be a great improvement and give more frequent lookup success to amend all the country code attributes to equal language code attributes (eg. it turns out mythical country Zolmovia (originally, code=Zm) speaks mainly Spanish (language code=es), so what am saying is change Zm to es in countries_attributed.xml) here)) make many changes of webpage obsolete.<\/p>\n<p><p>Today we build on  <a target=_blank href=\"#aacpt\" title='Ajax Auto-completion Primer Tutorial'>Ajax Auto-completion Primer Tutorial<\/a> as shown below, in that we attempt a (non 100% successful) coding relationship that tries to give a welcome message in the home language of the country you pick, via the wonderful <a target=_blank title='Google Translate' href='http:\/\/translate.google.com'>Google Translate<\/a>.<\/p>\n<p>One useful Ajax friendly piece of functionality is called auto-completion, where you have an HTML input text tag element you fill in, and you&#8217;d like to help out the user with both spelling and suggestions, so you present possibilities once they have pressed a key, and then the user can opt to pick one of the &#8220;(looks-like-a) dropdown&#8221;-listed options.  This often helps with the proper nouns in our life, or, as is the case with the tutorial, country names.  So we reward the user with a map courtesy of <a target=_blank title='Google Maps' href='http:\/\/maps.google.com'>Google Maps<\/a> (thanks) should it all go swimmingly (hope you&#8217;re not in <a target=_blank title='Chad' href='https:\/\/maps.google.com\/maps?q=Chad'>Chad<\/a> looking for a swim).  In addition, when successful in establishing a likely home language for your country (will be sometimes wrong, sometimes unknowable with the shortcuts here, and maybe sometimes wrong (for these we apologize)).<\/p>\n<p>Have a look at the HTML\/Javascript downloadable code which you could rename to <a target=_blank title='auto_language_complete.html' href=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/auto_language_complete.html-GETME\">auto_language_complete.html<\/a><\/p>\n<p>Here is a new link to some downloadable PHP programming source code explaining changes made (from tutorial below)  <a target=_blank title='column_chart_diff.php' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/auto_language_complete.html-GETME\">here<\/a>.<\/p>\n<p>Try a <a target=_blank title='live run' href=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/auto_language_complete.html\">live run<\/a> here.<\/p>\n<p>By the way, Gimp was used to make the layered image of this tutorial using techniques as explained in <a target=_blank tit='Gimp Layers Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5366'>Gimp Layers Primer Tutorial<\/a>.<\/p>\n<p>Regarding this topic I really like <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em> and the code in this book was followed closely, with small amendments.<\/p>\n<hr \/>\n<p d='aacpt'>Previous relevant <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5667\" title='Ajax Auto-completion Primer Tutorial'>Ajax Auto-completion Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Ajax Preview Window Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')\" id='aacpti'  onmouseover=\"var xqw=this.src; if (xqw.indexOf('1.png') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Completion_2.png'; } else if (xqw.indexOf('2.png') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Completion.png'; } else { this.src = 'http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Completion_1.png'; }\"   src=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/Auto_Completion.png\" title=\"Ajax Auto-completion Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Ajax Auto-completion Primer Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Ajax techniques make your web pages very dynamic and useful, and there will be fewer changes of webpage required when using Ajax, because information derived from a data source (maybe a feed, maybe a database read, maybe a local source of data (as for this tutorial&#8217;s <a target=_blank title='countries.xml' href='http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/countries.xml_GETME'>countries.xml<\/a> &#8230; thanks to <a target=_blank title='great help' href='http:\/\/trac.reddes.bvsalud.org\/projects\/scielo-submission\/browser\/branches\/ojs-2.3.3-1\/lib\/pkp\/locale\/en_US\/countries.xml'>link<\/a> here)) make many changes of webpage obsolete.<\/p>\n<p><p>Today we more or less build on your previous Ajax knowledge (which am sure has moved along a long way from) beginning (at least, at this blog) with <a target=_blank href=\"#apwt\" title='Ajax Preview Window Tutorial'>Ajax Preview Window Tutorial<\/a> as shown below.<\/p>\n<p>Let&#8217;s have a look at Wikipedia&#8217;s thoughts on Ajax <a target=_blank title='Ajax information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>below<\/a>.<\/p>\n<blockquote><p>Ajax (also AJAX; \/\u02c8e\u026ad\u0292\u00e6ks\/; an acronym for Asynchronous JavaScript and XML)[1] is a group of interrelated web development techniques used on the client-side to create asynchronous web applications. With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used instead. See AJAJ), and the requests do not need to be asynchronous.[2]<\/p>\n<p>Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and allow the user to interact with, the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.<\/p><\/blockquote>\n<p>One useful Ajax friendly piece of functionality is called auto-completion, where you have an HTML input text tag element you fill in, and you&#8217;d like to help out the user with both spelling and suggestions, so you present possibilities once they have pressed a key, and then the user can opt to pick one of the &#8220;(looks-like-a) dropdown&#8221;-listed options.  This often helps with the proper nouns in our life, or, as is the case with the tutorial, country names.  So we reward the user with a map courtesy of <a target=_blank title='Google Maps' href='http:\/\/maps.google.com'>Google Maps<\/a> (thanks) should it all go swimmingly (hope you&#8217;re not in <a target=_blank title='Chad' href='https:\/\/maps.google.com\/maps?q=Chad'>Chad<\/a> looking for a swim).<\/p>\n<p>Have a look at the HTML\/Javascript downloadable code which you could rename to <a target=_blank title='countries_auto_complete.html' href=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/countries_auto_complete.html_GETME\">countries_auto_complete.html<\/a><br \/>\nTry a <a target=_blank title='live run' href=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/AutoCompletion\/\">live run<\/a> here.<\/p>\n<p>By the way, Gimp was used to make the layered image of this tutorial using techniques as explained in <a target=_blank tit='Gimp Layers Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5366'>Gimp Layers Primer Tutorial<\/a>.<\/p>\n<p>Regarding this topic I really like <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em> and the code in this book was followed closely, with small amendments.<\/p>\n<hr \/>\n<p d='apwt'>Previous relevant <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=579\" title='Ajax Preview Window Tutorial'>Ajax Preview Window Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/ajax.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Ajax Preview Window Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Ajax\/Ajax.jpg\" title=\"Ajax Preview Window Tutorial\" \/><\/a><p class=\"wp-caption-text\">Ajax Preview Window Tutorial<\/p><\/div>\n<p>Ajax is a client-side meets server-side melding of PHP (or <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=1646'>ASP.Net<\/a>) and Javascript and HTML and CSS and allows you to stay on the web page you are on doing many more things, rather than constantly changing web pages the way that HTML form tag makes you do.  Ajax works with XMLHttpRequest object to quiz the server-side while staying on the client side.   You may have guessed that we have been working up to this, and I refer you to the previous tutorial about <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=574'>JavaScript and the DOM Tutorial<\/a> and <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=550'>PHP + JavaScript + HTML Primer Tutorial<\/a> for important information to learn before tackling Ajax.   Ajax shares similar restrictions to iFrames in limiting you to work within your own domain, generally speaking.   Ajax normally makes use of the onmouseover (hence the amateurish added rendition of a cursor, where I was hovering over the option tag, but couldn&#8217;t take a snapshot of this &#8230; ie. too lazy to get the camera!) and onmouseout events of HTML elements and you may notice the less than ideal Internet Explorer behaviour for this Ajax code, and that is because for Internet Explorer the option tag has no onmouseover nor onmouseout event defined, so we did an awful kludge.<\/p>\n<p><strong>Earlier tutorials &#8230; <\/strong><\/p>\n<p>JavaScript is a tremendous web client-side language to learn.   You may have heard of a server-side JavaScript, but this tutorial only deals with client-side work.   This tutorial builds a JavaScript layer on top of the <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=550'>PHP tutorial<\/a> made earlier, showing how the DOM can be used to change the look of your webpage dynamically, even if most of it is in an iFrame (but there are limits).<\/p>\n<p>PHP is a wonderful language to learn.   It is usually associated with being a web server-side language (as with this tutorial, where it is being shown on a local <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=532'>MAMP<\/a> web server) but can be a <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=262'>command line tool<\/a> as well.   If you like PHP you may eventually like <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=482'>ASP.Net<\/a> and\/or Python, and vice versa.   It has sophisticated data structures, Object Oriented (the thinking that you can build classes with data and methods which define objects created as you run the program &#8230; eg. you might write a class for book and have data members for things like numPages and publisher, author, creationDate and have methods called things like getCreationDate, setCreationDate, getAuthor, setAuthor allowing the user to use these methods rather than changing the  data members themselves &#8230; heaven forbid that!) code concepts, and really combines well with <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=293'>JavaScript<\/a> (as a client-side language).     <\/p>\n<p>Download programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Ajax\/ajax.php_GETME'>ajax.php<\/a> (but Ajax only works within the domain you use it, and this code mentions www.rjmprogramming.com.au so just use it for reference purposes or rewrite for purposes that suit you within your domain of interest).<\/p>\n<p>Regarding this  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/ajax.php'>topic<\/a> I really like <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em> <\/p>\n<p><strong><em>Did you know &#8230;<\/em><\/strong><br \/>\nJavaScript makes a great easy-access Calculator?<\/p>\n<p>Try typing the lines below into the address bar of your favourite browser:<\/p>\n<p>Javascript: eval(512 \/ 380);<br \/>\nJavascript: eval(512 * 380);<br \/>\nJavascript: eval(512 &#8211; 380);<br \/>\nJavascript: eval(512 + 380);<br \/>\nJavascript: eval(512 % 380);<\/p>\n<p>These days we spend so much time on the Internet it is a much quicker way to get to a calculator!\n<\/p>\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='#d579' onclick='var dv=document.getElementById(\"d579\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=63\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d579' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\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='#d5667' onclick='var dv=document.getElementById(\"d5667\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=63\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5667' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\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='#d5683' onclick='var dv=document.getElementById(\"d5683\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=63\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5683' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Ajax techniques make your web pages very dynamic and useful, and there will be fewer changes of webpage required when using Ajax, because information derived from a data source (maybe a feed, maybe a database read, maybe a local source &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/ajax-auto-completion-followup-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":[2,12,37],"tags":[69,281,527,532,576,652,997,1319,1480],"class_list":["post-5683","post","type-post","status-publish","format-standard","hentry","category-ajax","category-elearning","category-tutorials","tag-ajax","tag-css","tag-google-maps","tag-google-translate","tag-html","tag-javascript","tag-programming","tag-tutorial","tag-xml"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5683"}],"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=5683"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5683\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=5683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=5683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=5683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}