<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Client-side JavaScript &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/client-side-javascript/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>You think you know javascript. Quiz results!</title>
		<link>/2012/03/07/you-think-you-know-javascript-quiz-results/</link>
		<comments>/2012/03/07/you-think-you-know-javascript-quiz-results/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 10:27:37 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[quiz]]></category>
		<category><![CDATA[Client-side JavaScript]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=2854</guid>
		<description><![CDATA[After a week again, the &#8220;You think you know &#8230; JavaScript&#8221; quiz results are on! 1. Which loop is faster in JavaScript? for while correct answer 2. What will be alerted by the code bellow? var str = 'my-'; alert(str.split('-')[1]); Error An empty string correct answer &#8220;-&#8220; &#8220;my&#8221; 3. What is server-side JavaScript? JS scripts &#8230; <a href="/2012/03/07/you-think-you-know-javascript-quiz-results/" class="more-link">Continue reading <span class="screen-reader-text">You think you know javascript. Quiz results!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-algorithms-quiz-results/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>After a week again, the &#8220;You think you know &#8230; JavaScript&#8221; quiz results are on!</p>
<p><strong>1. Which loop is faster in JavaScript?</strong></p>
<ul>
<li>for</li>
<li>while <span style="color: #339966;">correct answer</span></li>
</ul>
<p><figure id="attachment_2883" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer1.png"><img src="/wp-content/uploads/2012/03/answer1.png" alt="Answers of the first question chart" title="Answers of the first question chart" width="600" height="371" class="size-full wp-image-2883" srcset="/wp-content/uploads/2012/03/answer1.png 600w, /wp-content/uploads/2012/03/answer1-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text"> </figcaption></figure><br />
<span id="more-2854"></span><br />
<strong>2. What will be alerted by the code bellow? </strong></p>
<pre lang="javascript">var str = 'my-'; alert(str.split('-')[1]);</pre>
<ul>
<li>Error</li>
<li>An empty string <span style="color: #339966;">correct answer</span></li>
<li>&#8220;-&#8220;</li>
<li>&#8220;my&#8221;</li>
</ul>
<figure id="attachment_2885" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer2.png"><img src="/wp-content/uploads/2012/03/answer2.png" alt="Answers of the second question chart" title="Answers of the second question chart" width="600" height="371" class="size-full wp-image-2885" srcset="/wp-content/uploads/2012/03/answer2.png 600w, /wp-content/uploads/2012/03/answer2-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text"> </figcaption></figure>
<p><strong>3. What is server-side JavaScript?</strong></p>
<ul>
<li>JS scripts files placed on the server that can be publicly accessed by the client</li>
<li>JS engine running on the server accessible via http <span style="color: #339966;">correct answer</span></li>
</ul>
<figure id="attachment_2887" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer3.png"><img src="/wp-content/uploads/2012/03/answer3.png" alt="Answers of the third question chart" title="Answers of the third question chart" width="600" height="371" class="size-full wp-image-2887" srcset="/wp-content/uploads/2012/03/answer3.png 600w, /wp-content/uploads/2012/03/answer3-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">90.91% right answers</figcaption></figure>
<p><strong>4. Is it possible to have private and public methods in a JavaScript object</strong></p>
<ul>
<li>Yes <span style="color: #339966;">correct answer</span></li>
<li>No</li>
</ul>
<figure id="attachment_2889" style="width: 540px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer4.png"><img src="/wp-content/uploads/2012/03/answer4.png" alt="Answers of the fourth question chart" title="Answers of the fourth question chart" width="540" height="331" class="size-full wp-image-2889" srcset="/wp-content/uploads/2012/03/answer4.png 540w, /wp-content/uploads/2012/03/answer4-300x183.png 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption class="wp-caption-text">54.55% answered with the right answer!</figcaption></figure>
<p><em>Note that the quiz will remain open, but no results will be published!</em></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-algorithms-quiz-results/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/03/07/you-think-you-know-javascript-quiz-results/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Zend Framework: Inject JavaScript Code in a Action/View</title>
		<link>/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/</link>
		<comments>/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 14:39:49 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Client-side JavaScript]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Printf]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=1666</guid>
		<description><![CDATA[There is a view helper that can inject a head or inline script into your code. Simply by putting some JavaScript code into the view script wont do the job, because the .phtml file is grabbed and parsed by the Zend Framework and thus the code there wont be parsed as JavaScript and it wont &#8230; <a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" class="more-link">Continue reading <span class="screen-reader-text">Zend Framework: Inject JavaScript Code in a Action/View</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>There is a view helper that can inject a head or inline script into your code.</p>
<p>Simply by putting some JavaScript code into the view script wont do the job, because the .phtml file is grabbed and parsed by the Zend Framework and thus the code there wont be parsed as JavaScript and it wont be executed as well by the browser.</p>
<h2>The Most Simple Way &#8230;</h2>
<p>is to put some place holder into the layout .phtml file and than from the controller&#8217;s action you can assign some JS code:</p>
<pre lang="php">
// layout.phtml
<?php
...
echo $this->layout()->scriptTags;
...
</pre>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{
	public function indexAction() 
	{
		$this->view->layout()->scriptTags = '<script src="my.js"></script>';	
	}	
}
</pre>
<h2>Solution No. 2</h2>
<p>Although the first solution is correct it&#8217;s not the most clearest way, because you put the JavaScript code into the PHP, and this sooner or later becomes a mess. </p>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{
	public function indexAction() 
	{
		$this->view->layout()->scriptTags = '<script src="my.js"></script>';
						  . '<script>alert("here\'s my" + "test")</script>';
	}	
}
</pre>
<p>The IDE is not highlighting the code, and you&#8217;ve to deal with too many quotes, which is bad! There is a better solution however &#8211; the inline script:</p>
<pre lang="php">
// script tags
/* @var $scripts Zend_View_Helper_InlineScript */
$scripts = $this->view->inlineScript();
$scripts->appendFile('my.js');
</pre>
<h2>Simply the Best</h2>
<p>Yeah, the best solution is something even better than the second one. Although the solution I&#8217;ve just mentioned is fine for including JS files, when you&#8217;ve to add some JS code you&#8217;ll have to put it again into the PHP. </p>
<pre lang="php">
$msg = 'some dynamically generated message';

// script tags
/* @var $scripts Zend_View_Helper_InlineScript */
$scripts = $this->view->inlineScript();
$scripts->appendFile('my.js');
$scripts->appendScript('alert("' . $msg . '")');
</pre>
<p>If there&#8217;s no relation between JavaScript and PHP you can simply put all this code into a separate .js file and load it from there. This is by the way the best solution because the file is cached by the browser, if the cache is enabled. But most of the time you perhaps have to send some variables from PHP to the JavaScript code.</p>
<p>It would be perfect if you had some kind of a variable placeholders &#8211; exactly as you have it in the Zend Framework&#8217;s view scripts!</p>
<h3>Another View</h3>
<p>This is completely possible &#8211; just forget about the default view &#8211; it renders the view script and it&#8217;s bind to the /views/scripts folder. You can make another, completely new, view instead! Here&#8217;s some source:</p>
<pre lang="php">
$view = new Zend_View();
$view->setBasePath('path_to_the_js_folder');

$view->msg = 'Some dynamically generated message';

// script tags
/* @var $scripts Zend_View_Helper_InlineScript */
$scripts = $this->view->inlineScript();
$scripts->appendFile('my.js');
$scripts->appendScript($view->render('inline.js'));
</pre>
<p>Thus now in the JS file you can have some placeholders!</p>
<pre lang="javascript">
// inline.js

// some js code
// ...
alert('<?php echo $this->msg ?>');
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
