{"id":20773,"date":"2016-03-19T03:01:07","date_gmt":"2016-03-18T17:01:07","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=20773"},"modified":"2016-03-19T05:35:54","modified_gmt":"2016-03-18T19:35:54","slug":"javascript-eval-functional-calls-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-eval-functional-calls-primer-tutorial\/","title":{"rendered":"Javascript Eval Functional Calls Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/text_musical_moods.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Eval Functional Calls Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/text_musical_moods.jpg\" title=\"Javascript Eval Functional Calls Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Eval Functional Calls Primer Tutorial<\/p><\/div>\n<p>As with &#8220;associative array&#8221; usage in Javascript which we last discussed with <a target=_blank title='Javascript Associative Array Mobile Friendly Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-associative-array-mobile-friendly-tutorial\/'>Javascript Associative Array Mobile Friendly Tutorial<\/a> where &#8220;names&#8221; take precedence over &#8220;number&#8221; (indexes) &#8230; transparency over obfuscation, if you like &#8230; and Javascript&#8217;s <a target=_blank title='Javascript eval() method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp'><i>eval()<\/i><\/a> method becomes so important, today we use Javascript in such a way that <i>eval<\/i> helps us code and document (just by coding) because a (SELECT element) dropdown&#8217;s values become the same as the Javascript function names, reminiscent (don&#8217;t you think?) of Function pointers in C and C++ that we discussed at this blog some time back with <a title='Function Pointers in C and C++ Primer Tutorial' href='#fpicacpt'>Function Pointers in C and C++ Primer Tutorial<\/a> as shown below.<\/p>\n<p>And so, we say here &#8230;<\/p>\n<blockquote><p>\nMake a friend of Javascript <i>eval<\/i>.\n<\/p><\/blockquote>\n<p> &#8230; as much as anything, because it&#8217;s unspeakable what Javascript <i>eval<\/i> does to you should you be unkind &#8230; <font size=1>but we digress<\/font>.<\/p>\n<p>Here we are being friends &#8230; <font size=1>but not being smarmy<\/font> &#8230; accessed after the SELECT element&#8217;s <i>onchange<\/i> event and after the INPUT element (text box) <i>onblur<\/i> event &#8230;<\/p>\n<p><code><br \/>\nfunction construct(textval, selval) {<br \/>\n  document.getElementById('td' + cnt + '_3').innerHTML=eval(selval + '(\"' + textval + '\")');<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; where var<font size=1>iable<\/font> <i>selval<\/i> represents one of those HTML SELECT element (dropdown) values and var<font size=1>iable<\/font> <i>textval<\/i> represents business logic.  Let&#8217;s make all this more transparent now.  What we do today is to ask for some text entered in interactively by the user, and in addition the user selects a &#8220;musical mood&#8221; HTML SELECT element (dropdown) value.  Our HTML and Javascript and CSS web application goes away and represents that mood with some HTML CSS text ideas displayed in an HTML table element cell (HTML td element) on the right hand side of that table&#8217;s current row (HTML tr element).  The web application then adds in another row for you, the user, to try again, as you see fit.  Pretty simple idea, huh?  Along the way, in a small way, we used the knowledge from yesterday&#8217;s <a title='CSS3 Web Fonts Primer Tutorial' href='#cwfpt'>CSS3 Web Fonts Primer Tutorial<\/a> as shown way below.<\/p>\n<p>And here&#8217;s some code for what we do if the user chooses <i>Crescendo<\/i> as their selected option from the dropdown &#8230;<\/p>\n<p><code><br \/>\nfunction Crescendo(thistext) {<br \/>\n  var rethtml='';<br \/>\n  for (var i=1; i&lt;=thistext.length; i++) {<br \/>\n    rethtml+='&lt;span style=color:' + cols[eval(i % cols.length)] + ';' + 'font-size:' + eval(2 * (i + 11)) + 'px;&gt;' + thistext.substring(eval(-1 + i), eval(0 + i)) + '&lt;\/span&gt;';<br \/>\n  }<br \/>\n  return rethtml;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Hopefully we got an <i>&#8220;ah&#8221;<\/i> moment out of readers who are new to this?!  This one may be revisited, to extend, but why not try this first draft as a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/text_musical_moods.html\" title='Click picture'>live run<\/a> and\/or examine the HTML and Javascript and CSS(3) you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/text_musical_moods.html_GETME\" title='text_musical_moods.html'>text_musical_moods.html<\/a>? (yes, it was a question)<\/p>\n<hr>\n<p id='fpicacpt'>Previous relevant <a target=_blank title='Function Pointers in C and C++ Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/function-pointers-in-c-and-c++-primer-tutorial\/'>Function Pointers in C and C++ 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\/CPlusPlus\/FunctionPointerArray\/\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Function Pointers in C and C++ Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/FunctionPointerArray\/C_Function_Pointers-6of.jpg\" title=\"Function Pointers in C and C++ Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Function Pointers in C and C++ Primer Tutorial<\/p><\/div>\n<p>When programming C and C++ you often talk about functions and methods respectively as a way to compartmentalize the work that your program needs to do.   Have you found yourself having these functions and methods well defined and similarly structured in terms of return types and argument types, yet doing different things, and you can define, in a switch statement, for instance, which one you&#8217;d want to do at any one particular part of your program execution.    This is where Function Pointers, optionally arranged into arrays, can be a good thing to learn about, as we do in this primer tutorial written in XCode C and C++.<\/p>\n<p><b>Background reading for tutorial:<\/p>\n<ul>\n<li><a target=_blank title='typedef' href='http:\/\/en.wikipedia.org\/wiki\/Typedef\u200e'>typedef<\/a><\/li>\n<li><a target=_blank title='arrays' href='http:\/\/en.wikipedia.org\/wiki\/Array_data_structure\u200e'>arrays<\/a><\/li>\n<li><a target=_blank title='pointers' href='http:\/\/en.wikipedia.org\/wiki\/Pointer_%28computer_programming%29'>pointers<\/a><\/li>\n<li><a target=_blank title='function pointers' href='http:\/\/en.wikipedia.org\/wiki\/Function_pointer'>function pointers<\/a><\/li>\n<li><a target=_blank title='switch' href='http:\/\/en.wikipedia.org\/wiki\/Switch_statement'>switch<\/a><\/li>\n<li><a target=_blank title='malloc' href='http:\/\/en.wikipedia.org\/wiki\/C_dynamic_memory_allocation'>malloc<\/a><\/li>\n<\/ul>\n<p><\/b>\n<\/p>\n<p>Here is a tutorial that introduces you to some C and C++ programming code for Function Pointers in an array &#8230;<\/p>\n<p>Let&#8217;s see some <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/FunctionPointerArray\/'>C and C++ via XCode<\/a> for this &#8230;<\/p>\n<p>Link to some downloadable C programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/FunctionPointerArray\/main.cpp_GETME' title='Download me'>main.cpp<\/a>  (or main.c &#8230; see how XCode can do C as well!) for use.<br \/>\nLink to some downloadable C++ programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/FunctionPointerArray\/main.cpp-GETME' title='Download me'>main.cpp<\/a>.\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='#d1376' onclick='var dv=document.getElementById(\"d1376\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=C%2B%2B\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d1376' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p id='cwfpt'>Previous relevant <a target=_blank title='CSS3 Web Fonts Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/css3-web-fonts-primer-tutorial\/'>CSS3 Web Fonts 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\/HTMLCSS\/css3_webfonts_rjm.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"CSS3 Web Fonts Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css3_webfonts_rjm.jpg\" title=\"CSS3 Web Fonts Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">CSS3 Web Fonts Primer Tutorial<\/p><\/div>\n<p><a target=_blank title='CSS3 information from w3schools' href='http:\/\/www.w3schools.com\/css\/css3_intro.asp'>CSS3<\/a> brought with it more possibilities regarding the use of <a target=_blank title='CSS3 Web Fonts information from w3schools' href='http:\/\/www.w3schools.com\/css\/css3_fonts.asp'>Web Fonts<\/a> (separate to your default fonts (or <a target=_blank title='Web Safe fonts information from w3schools' href='http:\/\/www.w3schools.com\/cssref\/css_websafe_fonts.asp'>&#8220;web safe&#8221;<\/a> fonts, that are usually installed)), and the use of &#8230;<\/p>\n<ol>\n<li>CSS3 @font-face rule<\/li>\n<li>linking of that @font-face rule to a &#8220;class definition&#8221;<\/li>\n<\/ol>\n<p> &#8230; as per &#8230; this code snippet from within today&#8217;s HTML within its &lt;head&gt; and &lt;\/head&gt; and within that &lt;style&gt; and &lt;\/style&gt;&#8230;<\/p>\n<p><code><br \/>\n@font-face {<br \/>\n    font-family: dashiconsFont;<br \/>\n    src: url(<b>http:\/\/www.rjmprogramming.com.au\/<\/b>ITblog\/wp-includes\/fonts\/dashicons.woff);<br \/>\n}<br \/>\n<b><\/b><br \/>\n.dashicons {<br \/>\n    font-family: dashiconsFont;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>So what&#8217;s the deal today?  Well, we thought we&#8217;d show you some CSS3 Web Fonts in action, those being the ones that happen to be hanging around our  (Apache hosting PHP and MySql) web server &#8230; <font size=1>minding their own business<\/font> &#8230; but happening during installs of CMS products like WordPress or Joomla.<\/p>\n<blockquote><p>\nBut how do you search for a CSS3 Web Font on your web server?\n<\/p><\/blockquote>\n<p> we hear you say &#8230; <font size=1>plaintively<\/font>.<\/p>\n<p>Well, the CSS3 Web Fonts are represented by files with the <i>.woff<\/i> extension &#8230; <font size=1>no, not <i>.woof<\/i> Nala<\/font>.<\/p>\n<p>So, on our Linux box (ie. our Linux web server computer) we gain access via <i>ssh<\/i> &#8230; <font size=1>as you would<\/font> &#8230; and issue the command (<b>bold<\/b> bits optional) &#8230;<\/p>\n<p><code><br \/>\nfind \/ -name '*.woff' 2> \/dev\/null <b>| grep -v '.woof'<\/b><br \/>\n<\/code><\/p>\n<p> &#8230; to help you (ie. your job here is to substitute your domain&#8217;s document root web server path for <b>domain landing page URL<\/b>) determine URL values you can place into the CSS3 @font-face rule <i>src<\/i> property.  If this is not making sense, take some time to read <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/cassini-webserver-primer-tutorial\/' title='Cassini++ WebServer Primer Tutorial'>Cassini++ WebServer Primer Tutorial<\/a>.<\/p>\n<p>If the web server is Windows, and you&#8217;ve <i>ssh<\/i>&#8216;ed to it, try the (DOS) command &#8230;<\/p>\n<p><code><br \/>\ndir c:\\*.woff \/s \/e <b>| find \/V '.woof'<\/b><br \/>\n<\/code><\/p>\n<p>To read more about <i>ssh<\/i> access to web servers, at this blog, please read <a target=_blank title='Web Server Access Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/web-server-access-primer-tutorial\/'>Web Server Access Primer Tutorial<\/a>.<\/p>\n<p>Yes &#8230; we are behoven &#8230; here is the behoved HTML and Javascript and CSS(3) programming source you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css3_webfonts_rjm.html_GETME\" title='css3_webfonts_rjm.html'>css3_webfonts_rjm.html<\/a> with this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css3_webfonts_rjm.html\" title='Click picture'>live run<\/a> link.<\/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='#d20752' onclick='var dv=document.getElementById(\"d20752\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/font\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d20752' 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='#d20773' onclick='var dv=document.getElementById(\"d20773\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/font\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d20773' style='display: none; border-left: 2px solid green; border-top:2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As with &#8220;associative array&#8221; usage in Javascript which we last discussed with Javascript Associative Array Mobile Friendly Tutorial where &#8220;names&#8221; take precedence over &#8220;number&#8221; (indexes) &#8230; transparency over obfuscation, if you like &#8230; and Javascript&#8217;s eval() method becomes so important, &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-eval-functional-calls-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,14,37],"tags":[281,282,354,399,400,471,473,576,652,1830,997,1319],"class_list":["post-20773","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-css","tag-css3","tag-dom","tag-eval","tag-event","tag-function","tag-function-pointers","tag-html","tag-javascript","tag-method","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20773"}],"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=20773"}],"version-history":[{"count":9,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20773\/revisions"}],"predecessor-version":[{"id":20786,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20773\/revisions\/20786"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=20773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=20773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=20773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}