<?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>[SMD] - 8L0G5PH3R3 &#187; Javascript</title>
	<atom:link href="http://www.sumardi.net/category/web-development/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sumardi.net</link>
	<description>/home/smd/public_html/blog</description>
	<lastBuildDate>Mon, 06 Feb 2012 13:30:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Script Type Or Language?</title>
		<link>http://www.sumardi.net/2007/05/23/script-type-or-language/</link>
		<comments>http://www.sumardi.net/2007/05/23/script-type-or-language/#comments</comments>
		<pubDate>Wed, 23 May 2007 05:25:34 +0000</pubDate>
		<dc:creator>SMD</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.sumardi.net/2007/05/23/script-type-or-language/</guid>
		<description><![CDATA[I&#8217;ve been asking myself, what is the difference between this tag: &#60;script language="javascript"&#62; and this tag: &#60;script type="text/javascript"&#62; After doing some googling, I found this documentation. The &#8220;language&#8221; specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F23%2Fscript-type-or-language%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F23%2Fscript-type-or-language%2F&amp;source=sumardi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve been asking myself, what is the difference between this tag:</p>
<p><code>&lt;script language="javascript"&gt;</code></p>
<p>and this tag:</p>
<p><code>&lt;script type="text/javascript"&gt;</code></p>
<p>After doing some <a href="http://www.google.com">googling</a>, I found <a href="http://www.w3.org/TR/html401/interact/scripts.html">this documentation</a>.</p>
<blockquote><p>The &#8220;language&#8221; specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been <strong>deprecated</strong> in favor of type.</p></blockquote>
<p>Therefore, you can say goodbye to <code>&lt;script language=""&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumardi.net/2007/05/23/script-type-or-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Loves JSON</title>
		<link>http://www.sumardi.net/2007/05/19/php-loves-json/</link>
		<comments>http://www.sumardi.net/2007/05/19/php-loves-json/#comments</comments>
		<pubDate>Fri, 18 May 2007 18:31:51 +0000</pubDate>
		<dc:creator>SMD</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://www.sumardi.net/2007/05/19/php-loves-json/</guid>
		<description><![CDATA[JSON is a format for communication between the server-side (PHP, JSP, ASP, etc&#8230;) and the client-side (javascript). The magic of it is that the response from the server-side can be easily converted to an object via the use of the eval() function. eval() (can be &#8220;evil&#8221;) is a function that gives you the possibility to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F19%2Fphp-loves-json%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F19%2Fphp-loves-json%2F&amp;source=sumardi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>JSON is a format for communication between the server-side (PHP, JSP, ASP, etc&#8230;) and the client-side (javascript). The magic of it is that the response from the server-side can be easily converted to an object via the use of the <code>eval()</code> function. <code>eval()</code> (can be &#8220;evil&#8221;) is a function that gives you the possibility to execute some code in javascript from a string. To use <code>eval()</code> is not a good idea. </p>
<p><strong>How can you JSON from PHP?</strong></p>
<p>If you are using PHP 5.2.x and above, you can simply use PHP built-in function, <code>json_encode()</code> and <code>json_decode().</code> This is an example how it works:</p>
<p>$i = array(<br />
                 array(&#8220;id&#8221; => 1, &#8220;name&#8221; => &#8220;sumardi&#8221;),<br />
                 array(&#8220;id&#8221; => 2, &#8220;name&#8221; => &#8220;hassan&#8221;),<br />
                 array(&#8220;id&#8221; => 3, &#8220;name&#8221; => &#8220;ruby&#8221;)<br />
        );</p>
<p>echo json_encode($i);</p>
<p>And it will echo :</p>
<p><code>[{"id":1,"name":"sumardi"},{"id":2,"name":"hassan"},{"id":3,"name":"ruby"}]</code></p>
<p><strong>How to JSON on Client-Side?</strong></p>
<p>Use the <code>eval()</code> function on the Server-Side JSON text response. And then you can call JSON like this:</p>
<p>for(var i = 0; i < json.length; i++)<br />
{<br />
    console.info(json.id + &#8221; &#8221; + json.name);<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumardi.net/2007/05/19/php-loves-json/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GoodBye alert()</title>
		<link>http://www.sumardi.net/2007/05/09/goodbye-alert/</link>
		<comments>http://www.sumardi.net/2007/05/09/goodbye-alert/#comments</comments>
		<pubDate>Tue, 08 May 2007 16:03:37 +0000</pubDate>
		<dc:creator>SMD</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.sumardi.net/2007/05/09/good-by-alert/</guid>
		<description><![CDATA[I have been working with Javascript and AJAX quite a bit recently. I always used alert() to debug something. At least to know that the script was able to call the method or something. This is annoying &#038; traditional way. I&#8217;m lazy to use Venkman. After doing some Googling about Firebug functionality, I found console.log(). [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F09%2Fgoodbye-alert%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F09%2Fgoodbye-alert%2F&amp;source=sumardi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I have been working with Javascript and AJAX quite a bit recently. I always used <code>alert()</code> to debug something. At least to know that the script was able to call the method or something.</p>
<p>saveBtn = dojo.widget.createWidget(&#8220;Button&#8221;, {caption: &#8220;Save Settings&#8221;}, dojo.byId(&#8220;saveBtn&#8221;));<br />
alert(saveBtn.caption);</p>
<p>This is annoying &#038; traditional way. I&#8217;m lazy to use <a href="http://www.mozilla.org/projects/venkman/">Venkman</a>. After doing some <a href="http://www.google.com">Googling</a> about <a href="http://www.firebug.com">Firebug</a> functionality, I found <code>console.log()</code>. Now, I can do same thing by using Firebug Console.</p>
<p>saveBtn = dojo.widget.createWidget(&#8220;Button&#8221;, {caption: &#8220;Save Settings&#8221;}, dojo.byId(&#8220;saveBtn&#8221;));<br />
console.log(saveBtn.caption);</p>
<p><a href="http://www.flickr.com/photos/sumardi/489961184/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/208/489961184_bdde6942e1.jpg" width="500" height="238" alt="console-log" /></a></p>
<p>At least it&#8217;s not messing up my screen. w00f! It also has different logging levels:</p>
<ul>
<li>console.debug()</li>
<li>console.info();</li>
<li>console.warn();</li>
<li>console.error();</li>
<li>console.trace();</li>
</ul>
<p>For more, <a href="http://www.getfirebug.com/console.html">Console API</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumardi.net/2007/05/09/goodbye-alert/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Var Or No Var</title>
		<link>http://www.sumardi.net/2007/05/04/var-or-no-var/</link>
		<comments>http://www.sumardi.net/2007/05/04/var-or-no-var/#comments</comments>
		<pubDate>Fri, 04 May 2007 15:15:24 +0000</pubDate>
		<dc:creator>SMD</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.sumardi.net/2007/05/04/var-or-no-var/</guid>
		<description><![CDATA[Over the past few weeks, I have been working with Dojo Toolkit. Dojo is a powerful javascript toolkit. In javascript, the var keyword is used to declare (or create) variables, but it is not required. What’s the difference between these two statements: a. var x =17; b. x = 17; Short answer. Statement (a) is [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F04%2Fvar-or-no-var%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.sumardi.net%2F2007%2F05%2F04%2Fvar-or-no-var%2F&amp;source=sumardi&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Over the past few weeks, I have been working with <a href="http://www.dojotoolkit.org">Dojo Toolkit</a>. Dojo is a powerful javascript toolkit. In javascript, the var keyword is used to declare (or create) variables, but it is not required. What’s the difference between these two statements:</p>
<blockquote><p>a. var x =17;<br />
b. x = 17;</p></blockquote>
<p>Short answer. Statement (a) is to create variable as a local variable and statement (b) is to create variable in the global scope. </p>
<p>Long answer. A variable declared outside a function is a global variable and a variable declared by assignment inside a function is also a global variable. A variable declared with var inside a function<br />
is a local variable, and is accessible only within that function.</p>
<p>For example, look at this code,<br />
<code><br />
&lt;script type="text/javascript"&gt;<br />
x1 = 2;<br />
var y1 = 2; </p>
<p>function setX2()<br />
{<br />
      x2 = 3;<br />
      var y2 = 3;<br />
}<br />
&lt;/script&gt;</code></p>
<p>Both x1 and y1 are global variable and are accessible everywhere in the global scope. But variable y2 is a local variable and x2 is global. Basically, to var or not to var is legal declaration. But it&#8217;s a good practice to use var because the variable is scoped to the correct execution context.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sumardi.net/2007/05/04/var-or-no-var/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

