<?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>Remember the code? &#187; Javascript and CSS</title>
	<atom:link href="http://code.neox.net/category/javascript-and-css/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.neox.net</link>
	<description>a place where I store my secret powerful coding snippets, or just to remember how to do things</description>
	<lastBuildDate>Fri, 19 Jun 2009 11:36:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SarahAjax Javascript Ajax Class</title>
		<link>http://code.neox.net/2008/06/03/sarahajax-javascript-ajax-class/</link>
		<comments>http://code.neox.net/2008/06/03/sarahajax-javascript-ajax-class/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 03:17:17 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[Javascript and CSS]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sarah]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=34</guid>
		<description><![CDATA[Download sarahajax.zip
Okay, here is my SarahAjax Javascript Class. You can use it without hassle!
You can either inherit and &#8216;action&#8217; function or by prototyping a function named &#8216;action&#8217;. &#8216;action&#8217; function will be called when the request to the resource is successful.
This is SarahAjax Class.

// 6/2/2008 HanaDaddy  hanadaddy at gmail.com
&#160;
/* SarahAjax is a very simple ajax [...]]]></description>
			<content:encoded><![CDATA[<p><a href='/sarahajax.zip'><strong>Download sarahajax.zip</strong></a></p>
<p>Okay, here is my SarahAjax Javascript Class. You can use it without hassle!</p>
<p>You can either inherit and &#8216;action&#8217; function or by prototyping a function named &#8216;action&#8217;. &#8216;action&#8217; function will be called when the request to the resource is successful.</p>
<p>This is SarahAjax Class.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #009900; font-style: italic;">// 6/2/2008 HanaDaddy  hanadaddy at gmail.com</span>
&nbsp;
<span style="color: #009900; font-style: italic;">/* SarahAjax is a very simple ajax class.
 * url: target url to call. It is usally dynamic script or a simple page return xml or text.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> SarahAjax<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">url</span>=url;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span> ; 
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">method</span>=<span style="color: #3366CC;">&quot;GET&quot;</span>;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">async</span>= <span style="color: #003366; font-weight: bold;">true</span>; <span style="color: #009900; font-style: italic;">//if false , the connection will be synchronous ( you have to wait for the reply)</span>
	<span style="color: #009900; font-style: italic;">//this.action = function (obj) { }  // Success reply handler. : youre responsibilty </span>
	<span style="color: #009900; font-style: italic;">//this.error  = function (obj) { }  // Error reply handler : your responsiblity to implement.	</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">sendRequest</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span> == <span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>window.<span style="color: #006600;">XMLHttpRequest</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span> = <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    			<span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>window.<span style="color: #006600;">ActiveXObject</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span> = <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&quot;</span><span style="color: #66cc66;">&#41;</span>;
    			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">action</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;SaraAjax:Action member function is not defined! We need the reply handler!&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000066; font-weight: bold;">return</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span>.<span style="color: #000066;">open</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">method</span>, <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">url</span>, <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">async</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> sajaxreq = <span style="color: #000066; font-weight: bold;">this</span>; <span style="color: #009900; font-style: italic;">// this is necessary to access myself in the callback function</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span>.<span style="color: #006600;">onreadystatechange</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> sajaxreq.<span style="color: #006600;">callback</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span>.<span style="color: #006600;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">callback</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span>.<span style="color: #006600;">readyState</span> == <span style="color: #CC0000;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span>.<span style="color: #000066;">status</span> == <span style="color: #CC0000;">200</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">//alert(&quot;reply is back?&quot;+this.reqobj.responseText);</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">action</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #66cc66;">&#123;</span>
			 	<span style="color: #009900; font-style: italic;">//alert(&quot;There was a problem retrieving data:\n&quot; + this.reqobj.statusText);</span>
			 	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">error</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			 		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">reqobj</span><span style="color: #66cc66;">&#41;</span>;
			 	<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>		
	<span style="color: #66cc66;">&#125;</span>	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><span id="more-34"></span><br />
<a href='/sarahajax/usage1.html'><strong>Click here for Usage Example1: Prototyping</strong></a><br />
How to use: </p>
<ol>
<li>Include the script <code>sarahajax.js</code> file in your html file.</li>
<li>Implement &#8216;<code>action</code>&#8216; function by prototyping. This function is only called when request reply is OK.</li>
<li>Optionally add &#8216;<code>error</code>&#8216; function. It is called by SarahAjax object when there was error occured or the request reply is not normal.
<li>Initialize a SarahAjax object with Target URL to send request to.</li>
<li>Call the object&#8217;s &#8216;<code>sendRequest()</code>&#8216; method to send request to the URL</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #66cc66;">&lt;</span>html<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>head<span style="color: #66cc66;">&gt;&lt;</span>title<span style="color: #66cc66;">&gt;</span>SarahAjax Testing <span style="color: #CC0000;">1</span> using prototyping<span style="color: #66cc66;">&lt;/</span>title<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&lt;</span>script type=<span style="color: #3366CC;">&quot;text/javascript&quot;</span> src=<span style="color: #3366CC;">&quot;sarahajax.js&quot;</span><span style="color: #66cc66;">&gt;&lt;/</span>script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>script type=<span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//The action function must have the  argument for XMLHttpRequest object</span>
SarahAjax.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">action</span>= <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">//obj.responseText : Regualar string</span>
	<span style="color: #009900; font-style: italic;">//obj.statusText : Showing Requst Result Status</span>
	<span style="color: #009900; font-style: italic;">//obj.responseXML : XML string</span>
	<span style="color: #003366; font-weight: bold;">var</span> div = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;result&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>div<span style="color: #66cc66;">&#41;</span>
		div.<span style="color: #006600;">innerHTML</span> = obj.<span style="color: #006600;">responseText</span>; 
	<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;hey where should I show the reply text?&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//error functino is optional, but it's a good idea to create one.</span>
SarahAjax.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">error</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>obj.<span style="color: #006600;">statusText</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Now create an object. The request will be sent to target_app.php</span>
<span style="color: #003366; font-weight: bold;">var</span> sajax = <span style="color: #003366; font-weight: bold;">new</span> SarahAjax<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;target_app.php&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
<span style="color: #66cc66;">&lt;/</span>script<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;</span>style type=<span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #66cc66;">&gt;</span>
#result <span style="color: #66cc66;">&#123;</span>
	border:1px dashed black;
	width:300px;
	height:30px;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&lt;</span><span style="color: #0066FF;">/style&gt;&lt;/</span>head<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>h2<span style="color: #66cc66;">&gt;</span>This <span style="color: #000066; font-weight: bold;">is</span> SarahAjax Testing Page<span style="color: #66cc66;">&lt;/</span>h2<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>div id=<span style="color: #3366CC;">&quot;result&quot;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #000066; font-weight: bold;">This</span> <span style="color: #000066; font-weight: bold;">is</span> where the result should show.
<span style="color: #66cc66;">&lt;/</span>div<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;</span>a href=<span style="color: #3366CC;">'javascript:sajax.sendRequest();'</span><span style="color: #66cc66;">&gt;</span>Send Request<span style="color: #66cc66;">&lt;/</span>a<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>body<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>html<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p><a href='/sarahajax/usage2.html'><strong>Click here for Usage Example2: inherit SarahAjax class</strong></a><br />
You can also use the class by creating a subclass. Please Click on the title to see the source in action. </p>
<p><a href='/sarahajax.zip'><strong>Download sarahajax.zip</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/06/03/sarahajax-javascript-ajax-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Class HowTo</title>
		<link>http://code.neox.net/2008/06/03/javascript-class-howto/</link>
		<comments>http://code.neox.net/2008/06/03/javascript-class-howto/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 04:29:18 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[Javascript and CSS]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=33</guid>
		<description><![CDATA[Great Tutorial on Javascript Classes

function Person &#40;firstname,lastname,age&#41;&#123;
&#160;
	this.firstname=firstname;
	this.lastname=lastname;
	this.age=age;
&#160;
	this.introduction = function &#40;type&#41; &#123;
		if &#40;type=='simple'&#41;&#123;
			alert&#40;&#34;Hi, I am &#34; + this.firstname +&#34;.&#34;&#41;;
		&#125;else&#123;
&#160;
			alert&#40;&#34;Hello, my name is &#34;+this.firstname + &#34; &#34; + this.lastname+&#34;.&#34; +
			 	&#34; I am &#34; + this.age + &#34; years old.&#34;&#41;;
		&#125;	
	&#125;
&#160;
&#125;
&#160;
var p = new Person&#40;&#34;Hana&#34;,&#34;Daddy&#34;,30&#41;;
&#160;
p.introduction&#40;&#34;simple&#34;&#41;;
p.introduction&#40;&#41;;

Creating a Javascript class is just like creating a regular function. Two things to [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.javascriptkit.com/javatutors/oopjs2.shtml'>Great Tutorial on Javascript Classes</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> Person <span style="color: #66cc66;">&#40;</span>firstname,lastname,age<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">firstname</span>=firstname;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">lastname</span>=lastname;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">age</span>=age;
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">introduction</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>type<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>type==<span style="color: #3366CC;">'simple'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Hi, I am &quot;</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">firstname</span> +<span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Hello, my name is &quot;</span>+<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">firstname</span> + <span style="color: #3366CC;">&quot; &quot;</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">lastname</span>+<span style="color: #3366CC;">&quot;.&quot;</span> +
			 	<span style="color: #3366CC;">&quot; I am &quot;</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">age</span> + <span style="color: #3366CC;">&quot; years old.&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>	
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> p = <span style="color: #003366; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Hana&quot;</span>,<span style="color: #3366CC;">&quot;Daddy&quot;</span>,<span style="color: #CC0000;">30</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
p.<span style="color: #006600;">introduction</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;simple&quot;</span><span style="color: #66cc66;">&#41;</span>;
p.<span style="color: #006600;">introduction</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Creating a Javascript class is just like creating a regular function. Two things to remember. </p>
<ul>
<li> Use <code>'this'</code> to access member variables.</li>
<li> How to define member functions </li>
</ul>
<p>The above will show alert message dialog.<br />
First, &#8220;Hi, I am Hana&#8221;.<br />
Second, &#8220;Hello, my name is Hana Daddy. I am 30 years old.&#8221;.</p>
<p>Now by using prototyping, you can add additional functions to the predefined classes. Also all the initialized class objects instantly have access to the new function! That is very convenient.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #009900; font-style: italic;">//Prototyping : add </span>
Person.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">addAge</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>year<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>year<span style="color: #66cc66;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">age</span> += year;
	<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">age</span> +=<span style="color: #CC0000;">1</span>;
<span style="color: #66cc66;">&#125;</span>
p.<span style="color: #006600;">addAge</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #66cc66;">&#41;</span>;
p.<span style="color: #006600;">introduction</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>The new <code>addAge</code> function was called from the previously created Person object p. And it&#8217;s working without problem. The Dialog says &#8220;Hello, my name is Hana Daddy. I am 35 years old.&#8221;. 5 years more aged. Time surely flies.</p>
<p>Finally, inheritance is very simple, too. See below example.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #009900; font-style: italic;">// new Person inherited class</span>
<span style="color: #003366; font-weight: bold;">function</span> GoodPerson<span style="color: #66cc66;">&#40;</span>firstname,lastname,age<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">fromClass</span> = Person;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">fromClass</span><span style="color: #66cc66;">&#40;</span>firstname,lastname,age<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">characteristic</span>=<span style="color: #3366CC;">&quot;Good&quot;</span>;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">doSomethingGood</span> =  <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;help others&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> a = <span style="color: #003366; font-weight: bold;">new</span> GoodPerson<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Good&quot;</span>,<span style="color: #3366CC;">&quot;Person&quot;</span>,<span style="color: #CC0000;">20</span><span style="color: #66cc66;">&#41;</span>;
a.<span style="color: #006600;">introduction</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Thats about a all for the quick HOWTO on Javascript class. I will post my very very simple Ajax Javascript Class next time. </p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/06/03/javascript-class-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE innerHTML property and NoScope element such as &lt;script&gt; and &lt;style&gt;</title>
		<link>http://code.neox.net/2008/06/02/ie-innerhtml-property-and-noscope-element-such-as-script-and-style/</link>
		<comments>http://code.neox.net/2008/06/02/ie-innerhtml-property-and-noscope-element-such-as-script-and-style/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 01:02:59 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[Javascript and CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=30</guid>
		<description><![CDATA[OK , I was working this my random sidebar image rotator. It uses ajax component to get html codes to show random images and it automatically rotates the image in every defined seconds.
In order to show horizontal and vertical images in a same spaced area, I have assigned pre defined squre div element and make [...]]]></description>
			<content:encoded><![CDATA[<p>OK , I was working this my random sidebar image rotator. It uses ajax component to get html codes to show random images and it automatically rotates the image in every defined seconds.</p>
<p>In order to show horizontal and vertical images in a same spaced area, I have assigned pre defined squre div element and make the ajax component to get html codes and set innetHTML property of this <code>&lt;div&gt;</code> element. The <code>&lt;img&gt;</code> element should be aligned in the center using calculated top and left CSS property.</p>
<p>So this is what I wanted to display (Normal) viewd with Firefox.<br />
<img src="http://code.neox.net/wp-content/uploads/2008/06/normal.jpg" alt="" title="normal" width="184" height="183" /></p>
<p>But when I tried with IE 7, I got below. It seems as if the <code>&lt;style&gt;</code> tag didn&#8217;t exist. The image was not aligned properly in the center.<br />
<img src="http://code.neox.net/wp-content/uploads/2008/06/abnormal.jpg" alt="" title="abnormal" width="184" height="183" /><br />
<span id="more-30"></span><br />
Here is my div injecting HTML code.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
.hana_ri {
	position: relative;
	width:180px;
	height:180px;
	/*border: 1px dashed grey;*/
}
&nbsp;
.hana_ri span {
	position: absolute;
	width: 51px;
	height: 19px;
	display:block;
&nbsp;
	top:80px;
	left:64px;
	background: url(http://localhost/wp/wp-content/themes/classic.neox/progress.gif) no-repeat;  
}
.hana_ri img {
	top:22.5px;
	left:0px;	
	position: absolute;
	width: 180px;
	height:135px;	
}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/wp/pics/IMG_2716.jpg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> 
<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://localhost/wp/wp-content/themes/classic.neox/hana_random_image.php?image=IMG_2716.jpg&quot;</span> 
<span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;IMG_2716.jpg&quot;</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri_span&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></pre></div></div>

<p>My code looks OK. I tried almost anything blaming and cursing the IE, why it has to be so difficult to do a simple thing. Searching Internet for any hints.</p>
<p>And I finally got my answer from Microsoft MSDN Website. <a href='http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx'>This is a link MSDN regarding innerHtml property</a> of html element. It&#8217;s a nice little reference about innerHTML property. If you keep scrolling down to the bottom, there is a comment made by a user. It&#8217;s title is  &#8220;How to inject NoScope elements into a page with innerHTML.&#8221; </p>
<p>This is the quote from the comment.</p>
<blockquote><p>
Internally, Internet Explorer treats the <code>&lt;script&gt;</code> tag as a NoScope element, which means (according to a rather opaque comment in the source) that &#8220;no text in a textrun should point to it.&#8221; Examples of other tags that have this attribute are HTML comments <code>(&lt;!-- --&gt;)</code> and STYLE tags. All NoScope elements are removed from the beginning of the parsed HTML before it is injected with innerHTML or insertAdjacentHTML. To prevent this from happening, you must include at least one scoped element at the beginning of the injected HTML.</p>
<p>To make it work, you must start the injected HTML string with a scoped element, preferably an invisible one like a hidden input element.
</p></blockquote>
<p>So basically the user is suggesting to start the innerHTML with the regular scoped element. He is suggesting to start with <code>&lt;input&gt;</code> with hidden attribute. If the innerHTML starts with <code>&lt;style&gt;</code>, IE will simply ignore it.</p>
<p>So I immediately changed the code and made the &lt;style&gt; to come after &lt;div&gt; element. And viola! , it worked just like a magic!!!!! I really appreciate &#8216;John Sudds&#8217;, the commenter.</p>
<p>So here is the final version that worked.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/wp/pics/IMG_2716.jpg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> 
<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://localhost/wp/wp-content/themes/classic.neox/hana_random_image.php?image=IMG_2716.jpg&quot;</span> 
<span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;IMG_2716.jpg&quot;</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri_span&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
.hana_ri {
	position: relative;
	width:180px;
	height:180px;
	/*border: 1px dashed grey;*/
}
&nbsp;
.hana_ri span {
	position: absolute;
	width: 51px;
	height: 19px;
	display:block;
&nbsp;
	top:80px;
	left:64px;
	background: url(http://localhost/wp/wp-content/themes/classic.neox/progress.gif) no-repeat;  
}
.hana_ri img {
	top:22.5px;
	left:0px;	
	position: absolute;
	width: 180px;
	height:135px;	
}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/06/02/ie-innerhtml-property-and-noscope-element-such-as-script-and-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
