<?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>JaffnaCampus.com &#187; Javascript</title>
	<atom:link href="http://jaffnacampus.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://jaffnacampus.com</link>
	<description>Gateway to your IT potential</description>
	<lastBuildDate>Tue, 27 Sep 2011 13:57:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript Create Your Own Objects</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-create-your-own-objects/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-create-your-own-objects/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:55:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Create Your Own Objects]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=281</guid>
		<description><![CDATA[Objects are useful to organize information.

JavaScript Objects
Earlier in this tutorial we have seen that JavaScript has several   built-in [...]]]></description>
			<content:encoded><![CDATA[<p>Objects are useful to organize information.</p>
<hr />
<h2>JavaScript Objects</h2>
<p>Earlier in this tutorial we have seen that JavaScript has several   built-in objects, like String, Date, Array, and more.  In addition to these built-in objects, you can also create your own.</p>
<p>An object is just a special kind of data, with a collection of   properties and methods.</p>
<p>Let&#8217;s illustrate with an example: A person is an object. Properties   are the values associated with the object. The persons&#8217;   properties include name, height, weight, age, skin tone, eye color, etc.   All persons have these properties, but the values of those properties   will differ from   person to person. Objects also have methods. Methods are the actions   that can be performed on objects. The persons&#8217; methods could be eat(),   sleep(), work(), play(), etc.</p>
<h3>Properties</h3>
<p>The syntax for accessing a property of an object is:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>objName.propName</td>
</tr>
</tbody>
</table>
<p>You can add properties to an object by simply giving it a value.   Assume that the personObj already exists &#8211;  you can give it properties named firstname, lastname, age, and eyecolor   as follows:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> personObj.firstname=&quot;John&quot;;<br />
        personObj.lastname=&quot;Doe&quot;;<br />
        personObj.age=30;<br />
        personObj.eyecolor=&quot;blue&quot;;</p>
<p>        document.write(personObj.firstname);</td>
</tr>
</tbody>
</table>
<p>The code above will generate the following output:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>John</td>
</tr>
</tbody>
</table>
<h3>Methods</h3>
<p>An object can also contain methods.</p>
<p>You can call a method with the following syntax:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>objName.methodName()</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Parameters required for the method can be passed between   the parentheses.</p>
<p>To call a method called sleep() for the personObj:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>personObj.sleep();</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>Creating Your Own Objects</h2>
<p>There are different ways to create a new object:</p>
<p><strong>1. Create a direct instance of an object</strong></p>
<p>The following code creates an instance of an object and adds four   properties to it:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> personObj=new Object();<br />
        personObj.firstname=&quot;John&quot;;<br />
        personObj.lastname=&quot;Doe&quot;;<br />
        personObj.age=50;<br />
        personObj.eyecolor=&quot;blue&quot;;</td>
</tr>
</tbody>
</table>
<p>Adding a method to the personObj is also simple. The following code   adds a method called eat() to the personObj:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>personObj.eat=eat;</td>
</tr>
</tbody>
</table>
<p><strong>2. Create a template of an object</strong></p>
<p>The template defines the structure of an object:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function person(firstname,lastname,age,eyecolor)<br />
        {<br />
        this.firstname=firstname;<br />
        this.lastname=lastname;<br />
        this.age=age;<br />
        this.eyecolor=eyecolor;<br />
        }</td>
</tr>
</tbody>
</table>
<p>Notice that the template is just a function. Inside the function you   need to   assign things to this.propertyName. The reason for all the &quot;this&quot; stuff   is that you&#8217;re going   to have more than one person at a time (which person you&#8217;re dealing with   must be   clear). That&#8217;s what &quot;this&quot; is: the instance of the object at hand.</p>
<p>Once you have the template, you can create new instances of the   object, like this:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> myFather=new person(&quot;John&quot;,&quot;Doe&quot;,50,&quot;blue&quot;);  myMother=new person(&quot;Sally&quot;,&quot;Rally&quot;,48,&quot;green&quot;);</td>
</tr>
</tbody>
</table>
<p>You can also add some methods to the person object. This is also done   inside the template:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function person(firstname,lastname,age,eyecolor)<br />
        {<br />
        this.firstname=firstname;<br />
        this.lastname=lastname;<br />
        this.age=age;<br />
        this.eyecolor=eyecolor;</p>
<p>        this.newlastname=newlastname;<br />
        }</td>
</tr>
</tbody>
</table>
<p>Note that methods are just functions attached to objects. Then we   will have to write the newlastname() function:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function newlastname(new_lastname)<br />
        {<br />
        this.lastname=new_lastname;<br />
        }</td>
</tr>
</tbody>
</table>
<p>The newlastname() function defines the person&#8217;s new last name and   assigns that to the person. JavaScript knows which person you&#8217;re   talking about by using &quot;this.&quot;. So, now you can write:   myMother.newlastname(&quot;Doe&quot;).</p>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-create-your-own-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Timing Events</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-timing-events/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-timing-events/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:54:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Timing Events]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=279</guid>
		<description><![CDATA[JavaScript Timing Events
With JavaScript, it is possible to execute some code after a   specified time-interval. This is called [...]]]></description>
			<content:encoded><![CDATA[<h2>JavaScript Timing Events</h2>
<p>With JavaScript, it is possible to execute some code after a   specified time-interval. This is called timing events.</p>
<p>It&#8217;s very easy to time events in JavaScript. The two key methods that   are used are:</p>
<ul>
<li>setTimeout() &#8211; executes a code some time in the future</li>
<li>clearTimeout() &#8211; cancels the setTimeout()</li>
</ul>
<p><strong>Note:</strong> The setTimeout() and clearTimeout() are both methods of   the HTML DOM Window object.</p>
<hr />
<h2>The setTimeout() Method</h2>
<h3><strong>Syntax</strong></h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>var t=setTimeout(&quot;<em>javascript statement</em>&quot;,<em>milliseconds</em>);</td>
</tr>
</tbody>
</table>
<p>The setTimeout() method returns a value &#8211; In the statement above, the   value is stored in a variable called t.  If you want to cancel this setTimeout(), you can refer to it using the   variable name.</p>
<p>The first parameter of setTimeout() is a string that contains a   JavaScript statement. This statement could be a statement  like &quot;alert(&#8216;5 seconds!&#8217;)&quot; or a call to a function, like &quot;alertMsg()&quot;.</p>
<p>The second parameter indicates how many milliseconds from now you   want to execute the first parameter. </p>
<p><strong>Note:</strong> There are 1000 milliseconds in one second.</p>
<h3>Example</h3>
<p>When the button is clicked in the example below, an alert box will be   displayed after 5 seconds.</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                function timedMsg()<br />
                {<br />
                var t=setTimeout(&quot;alert(&#8216;5 seconds!&#8217;)&quot;,5000);<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;form&gt;<br />
                &lt;input type=&quot;button&quot; value=&quot;Display timed alertbox!&quot;<br />
                onClick=&quot;timedMsg()&quot; /&gt;<br />
                &lt;/form&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<h3>Example &#8211; Infinite Loop</h3>
<p>To get a timer to work in an infinite loop, we must write a function   that   calls itself.</p>
<p>In the example below, when a button is clicked, the input field   will start to count (for ever), starting at 0.</p>
<p>Notice that we also have a function that checks if the timer is   already   running, to avoid creating additional timers, if the button is pressed   more than   once:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var c=0;<br />
                var t;<br />
                var timer_is_on=0;</p>
<p>                function timedCount()<br />
                {<br />
                document.getElementById(&#8216;txt&#8217;).value=c;<br />
                c=c+1;<br />
                t=setTimeout(&quot;timedCount()&quot;,1000);<br />
                }</p>
<p>                function doTimer()<br />
                {<br />
                if (!timer_is_on)<br />
                {<br />
                timer_is_on=1;<br />
                timedCount();<br />
                }<br />
                }<br />
                &lt;/script&gt; <br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;form&gt;<br />
                &lt;input type=&quot;button&quot; value=&quot;Start count!&quot; onClick=&quot;doTimer()&quot;&gt;<br />
                &lt;input type=&quot;text&quot; id=&quot;txt&quot; /&gt;<br />
                &lt;/form&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>The clearTimeout() Method</h2>
<h3><strong>Syntax</strong></h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>clearTimeout(<em>setTimeout_variable</em>)</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<p>The example below is the same as the &quot;Infinite Loop&quot; example above.   The only   difference is that we have now added a &quot;Stop Count!&quot; button that stops   the timer:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var c=0;<br />
                var t;<br />
                var timer_is_on=0;</p>
<p>                function timedCount()<br />
                {<br />
                document.getElementById(&#8216;txt&#8217;).value=c;<br />
                c=c+1;<br />
                t=setTimeout(&quot;timedCount()&quot;,1000);<br />
                }</p>
<p>                function doTimer()<br />
                {<br />
                if (!timer_is_on)<br />
                {<br />
                timer_is_on=1;<br />
                timedCount();<br />
                }<br />
                }</p>
<p>                function stopCount()<br />
                {<br />
                clearTimeout(t);<br />
                timer_is_on=0;<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;form&gt;<br />
                &lt;input type=&quot;button&quot; value=&quot;Start count!&quot; onClick=&quot;doTimer()&quot;&gt;<br />
                &lt;input type=&quot;text&quot; id=&quot;txt&quot;&gt;<br />
                &lt;input type=&quot;button&quot; value=&quot;Stop count!&quot; onClick=&quot;stopCount()&quot;&gt;<br />
                &lt;/form&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-timing-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Image Maps</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-image-maps/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-image-maps/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:49:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Image Maps]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=277</guid>
		<description><![CDATA[An image-map is an image with clickable regions.

HTML Image Maps
From our HTML tutorial we have learned that an image-map is [...]]]></description>
			<content:encoded><![CDATA[<p>An image-map is an image with clickable regions.</p>
<hr />
<h2>HTML Image Maps</h2>
<p>From our HTML tutorial we have learned that an image-map is an image   with clickable regions. Normally, each region has an   associated hyperlink. Clicking on one of the regions takes you to the   associated link.</p>
<hr />
<h2>Adding some JavaScript</h2>
<p>We can add events (that can call a JavaScript) to the &lt;area&gt;   tags inside the   image map. The &lt;area&gt; tag supports the onClick, onDblClick,   onMouseDown,   onMouseUp, onMouseOver, onMouseMove, onMouseOut, onKeyPress, onKeyDown,   onKeyUp, onFocus, and onBlur events.</p>
<p>Here&#8217;s the HTML image-map example, with some JavaScript added:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                function writeText(txt)<br />
                {<br />
                document.getElementById(&quot;desc&quot;).innerHTML=txt;<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;img src=&quot;planets.gif&quot; width=&quot;145&quot; height=&quot;126&quot;<br />
                alt=&quot;Planets&quot; usemap=&quot;#planetmap&quot; /&gt;</p>
<p>                &lt;map name=&quot;planetmap&quot;&gt;<br />
                &lt;area shape =&quot;rect&quot; coords =&quot;0,0,82,126&quot;<br />
                onMouseOver=&quot;writeText(&#8216;The Sun and the gas giant planets like Jupiter<br />
                are by far the largest objects in our Solar System.&#8217;)&quot;<br />
                href =&quot;sun.htm&quot; target =&quot;_blank&quot; alt=&quot;Sun&quot; /&gt;</p>
<p>                &lt;area shape =&quot;circle&quot; coords =&quot;90,58,3&quot;<br />
                onMouseOver=&quot;writeText(&#8216;The planet Mercury is very difficult to study<br />
                from the Earth because it is always so close to the Sun.&#8217;)&quot;<br />
                href =&quot;mercur.htm&quot; target =&quot;_blank&quot; alt=&quot;Mercury&quot; /&gt;</p>
<p>                &lt;area shape =&quot;circle&quot; coords =&quot;124,58,8&quot;<br />
                onMouseOver=&quot;writeText(&#8216;Until the 1960s, Venus was often considered a<br />
                twin sister to the Earth because Venus is the nearest planet to us, and<br />
                because the two planets seem to share many characteristics.&#8217;)&quot;<br />
                href =&quot;venus.htm&quot; target =&quot;_blank&quot; alt=&quot;Venus&quot; /&gt;<br />
                &lt;/map&gt;</p>
<p>                &lt;p id=&quot;desc&quot;&gt;&lt;/p&gt;</p>
<p>                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-image-maps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Animation</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-animation/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-animation/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:47:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Animation]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=274</guid>
		<description><![CDATA[With JavaScript we can create animated images.

JavaScript Animation
It is possible to use JavaScript to create animated images.
The trick is to [...]]]></description>
			<content:encoded><![CDATA[<p>With JavaScript we can create animated images.</p>
<hr />
<h2>JavaScript Animation</h2>
<p>It is possible to use JavaScript to create animated images.</p>
<p>The trick is to let a JavaScript change between different images on   different events.</p>
<p>In the following example we will add an image that should act as a   link button on   a web page. We will then add an onMouseOver event and an onMouseOut   event that will run   two JavaScript functions that will change between the images.</p>
<hr />
<h2>The HTML Code</h2>
<p>The HTML code looks like this:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;a href=&quot;http://JaffnaCampus.com&quot; target=&quot;_blank&quot;&gt;<br />
        &lt;img border=&quot;0&quot; alt=&quot;Visit Jaffna Campus!&quot; src=&quot;b_pink.gif&quot;   id=&quot;b1&quot;<br />
        onmouseOver=&quot;mouseOver()&quot; onmouseOut=&quot;mouseOut()&quot; /&gt;&lt;/a&gt;</td>
</tr>
</tbody>
</table>
<p>Note that we have given the image an id, to make it possible for a   JavaScript to address it later.</p>
<p>The onMouseOver event tells the browser that once a mouse is rolled   over the image, the browser should execute a function that will replace   the image with another image.</p>
<p>The onMouseOut event tells the browser that once a mouse is rolled   away from the image, another JavaScript function should be executed.   This   function will insert the original image again.</p>
<hr />
<h2>The JavaScript Code</h2>
<p>The changing between the images is done with the following   JavaScript:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;script type=&quot;text/javascript&quot;&gt;<br />
        function mouseOver()<br />
        {<br />
        document.getElementById(&quot;b1&quot;).src =&quot;b_blue.gif&quot;;<br />
        }<br />
        function mouseOut()<br />
        {<br />
        document.getElementById(&quot;b1&quot;).src =&quot;b_pink.gif&quot;;<br />
        }<br />
        &lt;/script&gt;</td>
</tr>
</tbody>
</table>
<p>The function mouseOver() causes the image to shift to &quot;b_blue.gif&quot;.</p>
<p>The function mouseOut() causes the image to shift to &quot;b_pink.gif&quot;.</p>
<hr />
<h2>The Entire Code</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                function mouseOver()<br />
                {<br />
                document.getElementById(&quot;b1&quot;).src =&quot;b_blue.gif&quot;;<br />
                }<br />
                function mouseOut()<br />
                {<br />
                document.getElementById(&quot;b1&quot;).src =&quot;b_pink.gif&quot;;<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;a href=&quot;http://JaffnaCampus.com&quot; target=&quot;_blank&quot;&gt;<br />
                &lt;img border=&quot;0&quot; alt=&quot;Visit Jaffna Campus!&quot; src=&quot;b_pink.gif&quot;   id=&quot;b1&quot;<br />
                onmouseover=&quot;mouseOver()&quot; onmouseout=&quot;mouseOut()&quot; /&gt;&lt;/a&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-animation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Form Validation</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-form-validation/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-form-validation/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:43:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Form Validation]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=271</guid>
		<description><![CDATA[JavaScript Form Validation
JavaScript can be used to validate data in HTML forms before sending   off the content to [...]]]></description>
			<content:encoded><![CDATA[<h2>JavaScript Form Validation</h2>
<p>JavaScript can be used to validate data in HTML forms before sending   off the content to a server.</p>
<p>Form data that typically are checked by a JavaScript could be:</p>
<ul>
<li>has the user left required fields empty?</li>
<li>has the user entered a valid e-mail address?</li>
<li>has the user entered a valid date?</li>
<li>has the user entered text in a numeric field?</li>
</ul>
<hr />
<h2>Required Fields</h2>
<p>The function below checks if a required field has been left empty. If   the required field is blank, an alert box alerts a message and the   function returns   false. If a value is entered, the function returns true (means that data   is OK):</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function validate_required(field,alerttxt)<br />
        {<br />
        with (field)<br />
        {<br />
        if (value==null||value==&quot;&quot;)<br />
        {<br />
        alert(alerttxt);return false;<br />
        }<br />
        else<br />
        {<br />
        return true;<br />
        }<br />
        }<br />
        }</td>
</tr>
</tbody>
</table>
<p>The entire script, with the HTML form could look something like this:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
        &lt;head&gt;<br />
        &lt;script type=&quot;text/javascript&quot;&gt;<br />
        function validate_required(field,alerttxt)<br />
        {<br />
        with (field)<br />
        {<br />
        if (value==null||value==&quot;&quot;)<br />
        {<br />
        alert(alerttxt);return false;<br />
        }<br />
        else<br />
        {<br />
        return true;<br />
        }<br />
        }<br />
        }</p>
<p>        function validate_form(thisform)<br />
        {<br />
        with (thisform)<br />
        {<br />
        if (validate_required(email,&quot;Email must be filled out!&quot;)==false)<br />
        {email.focus();return false;}<br />
        }<br />
        }<br />
        &lt;/script&gt;<br />
        &lt;/head&gt;</p>
<p>        &lt;body&gt;<br />
        &lt;form action=&quot;submit.htm&quot;  onsubmit=&quot;return validate_form(this)&quot;  method=&quot;post&quot;&gt;<br />
        Email: &lt;input type=&quot;text&quot; name=&quot;email&quot; size=&quot;30&quot;&gt;<br />
        &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;<br />
        &lt;/form&gt;<br />
        &lt;/body&gt;</p>
<p>        &lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>E-mail Validation</h2>
<p>The function below checks if the content has the general syntax of an   email.</p>
<p>This means that the input data must contain at least an @ sign and a   dot (.).   Also, the @ must not be the first character of the email address, and   the last   dot must at least be one character after the @ sign:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function validate_email(field,alerttxt)<br />
        {<br />
        with (field)<br />
        {<br />
        apos=value.indexOf(&quot;@&quot;);<br />
        dotpos=value.lastIndexOf(&quot;.&quot;);<br />
        if (apos&lt;1||dotpos-apos&lt;2)<br />
        {alert(alerttxt);return false;}<br />
        else {return true;}<br />
        }<br />
        }</td>
</tr>
</tbody>
</table>
<p>The entire script, with the HTML form could look something like this:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
        &lt;head&gt;<br />
        &lt;script type=&quot;text/javascript&quot;&gt;<br />
        function validate_email(field,alerttxt)<br />
        {<br />
        with (field)<br />
        {<br />
        apos=value.indexOf(&quot;@&quot;);<br />
        dotpos=value.lastIndexOf(&quot;.&quot;);<br />
        if (apos&lt;1||dotpos-apos&lt;2)<br />
        {alert(alerttxt);return false;}<br />
        else {return true;}<br />
        }<br />
        }</p>
<p>        function validate_form(thisform)<br />
        {<br />
        with (thisform)<br />
        {<br />
        if (validate_email(email,&quot;Not a valid e-mail address!&quot;)==false)<br />
        {email.focus();return false;}<br />
        }<br />
        }<br />
        &lt;/script&gt;<br />
        &lt;/head&gt;</p>
<p>        &lt;body&gt;<br />
        &lt;form action=&quot;submit.htm&quot;  onsubmit=&quot;return validate_form(this);&quot;  method=&quot;post&quot;&gt;<br />
        Email: &lt;input type=&quot;text&quot; name=&quot;email&quot; size=&quot;30&quot;&gt;<br />
        &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;<br />
        &lt;/form&gt;<br />
        &lt;/body&gt;</p>
<p>        &lt;/html&gt;</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-form-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Cookies</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-cookies/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-cookies/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:42:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Cookies]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=269</guid>
		<description><![CDATA[A cookie is often used to identify a user.

What is a Cookie? 
A cookie is a variable that is stored [...]]]></description>
			<content:encoded><![CDATA[<p>A cookie is often used to identify a user.</p>
<hr />
<h2>What is a Cookie? </h2>
<p>A cookie is a variable that is stored on the visitor&#8217;s computer. Each     time the same computer requests a page with a browser, it will send the   cookie   too. With JavaScript, you can both create and retrieve cookie values.</p>
<p>Examples of cookies:</p>
<ul>
<li>Name cookie &#8211; The first time a visitor arrives to your web page, he   or   	she must fill in her/his name. The name is then stored in a cookie.   Next   	time the visitor arrives at your page, he or she could get a welcome   message   	like &quot;Welcome John Doe!&quot; The name is retrieved from the stored cookie</li>
<li>Password cookie &#8211; The first time a visitor arrives to your web   page, he   	or she must fill in a password. The password is then stored in a   cookie.   	Next time the visitor arrives at your page, the password is retrieved   from   	the cookie</li>
<li>Date cookie &#8211; The first time a visitor arrives to your web page,   the   	current date is stored in a cookie. Next time the visitor arrives at   your   	page, he or she could get a message like &quot;Your last visit was on   Tuesday   	August 11, 2005!&quot; The date is retrieved from the stored cookie</li>
</ul>
<hr />
<h2>Create and Store a Cookie</h2>
<p>In this example we will create a cookie that stores the name of a   visitor.   The first time a visitor arrives to the web page, he or she will be   asked to    fill in her/his name. The name is then stored in a cookie. The next time   the   visitor arrives at the same page, he or she will get welcome message.</p>
<p>First, we create a function that stores the name of the visitor in a   cookie variable:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function setCookie(c_name,value,expiredays)<br />
        {<br />
        var exdate=new Date();<br />
        exdate.setDate(exdate.getDate()+expiredays);<br />
        document.cookie=c_name+ &quot;=&quot; +escape(value)+<br />
        ((expiredays==null) ? &quot;&quot; : &quot;;expires=&quot;+exdate.toGMTString());<br />
        }</td>
</tr>
</tbody>
</table>
<p>The parameters of the function above hold the name of the cookie, the   value of the cookie, and the number of days until the cookie expires.</p>
<p>In the function above we first convert the number of days to a valid   date, then we add the number of days until the cookie should expire.   After that we store the cookie name, cookie value and the expiration   date in the document.cookie object.</p>
<p>Then, we create another function that checks if the cookie has been   set:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function getCookie(c_name)<br />
        {<br />
        if (document.cookie.length&gt;0)<br />
        {<br />
        c_start=document.cookie.indexOf(c_name + &quot;=&quot;);<br />
        if (c_start!=-1)<br />
        {<br />
        c_start=c_start + c_name.length+1;<br />
        c_end=document.cookie.indexOf(&quot;;&quot;,c_start);<br />
        if (c_end==-1) c_end=document.cookie.length;<br />
        return unescape(document.cookie.substring(c_start,c_end));<br />
        }<br />
        }<br />
        return &quot;&quot;;<br />
        }</td>
</tr>
</tbody>
</table>
<p>The function above first checks if a cookie is stored at all in the   document.cookie object. If the document.cookie object holds some   cookies, then   check to see if our specific cookie is stored. If our cookie is found,   then return the value, if not &#8211; return an empty string.</p>
<p>Last, we create the function that displays a welcome message if the   cookie is set, and if the cookie is not set it will display a prompt   box, asking for the   name of the user:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function checkCookie()<br />
        {<br />
        username=getCookie(&#8216;username&#8217;);<br />
        if (username!=null &amp;&amp; username!=&quot;&quot;)<br />
        {<br />
        alert(&#8216;Welcome again &#8216;+username+&#8217;!');<br />
        }<br />
        else<br />
        {<br />
        username=prompt(&#8216;Please enter your name:&#8217;,&quot;&quot;);<br />
        if (username!=null &amp;&amp; username!=&quot;&quot;)<br />
        {<br />
        setCookie(&#8216;username&#8217;,username,365);<br />
        }<br />
        }<br />
        }</td>
</tr>
</tbody>
</table>
<p>All together now:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                function getCookie(c_name)<br />
                {<br />
                if (document.cookie.length&gt;0)<br />
                {<br />
                c_start=document.cookie.indexOf(c_name + &quot;=&quot;);<br />
                if (c_start!=-1)<br />
                {<br />
                c_start=c_start + c_name.length+1;<br />
                c_end=document.cookie.indexOf(&quot;;&quot;,c_start);<br />
                if (c_end==-1) c_end=document.cookie.length;<br />
                return unescape(document.cookie.substring(c_start,c_end));<br />
                }<br />
                }<br />
                return &quot;&quot;;<br />
                }</p>
<p>                function setCookie(c_name,value,expiredays)<br />
                {<br />
                var exdate=new Date();<br />
                exdate.setDate(exdate.getDate()+expiredays);<br />
                document.cookie=c_name+ &quot;=&quot; +escape(value)+<br />
                ((expiredays==null) ? &quot;&quot; : &quot;;expires=&quot;+exdate.toGMTString());<br />
                }</p>
<p>                function checkCookie()<br />
                {<br />
                username=getCookie(&#8216;username&#8217;);<br />
                if (username!=null &amp;&amp; username!=&quot;&quot;)<br />
                {<br />
                alert(&#8216;Welcome again &#8216;+username+&#8217;!');<br />
                }<br />
                else<br />
                {<br />
                username=prompt(&#8216;Please enter your name:&#8217;,&quot;&quot;);<br />
                if (username!=null &amp;&amp; username!=&quot;&quot;)<br />
                {<br />
                setCookie(&#8216;username&#8217;,username,365);<br />
                }<br />
                }<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body onload=&quot;checkCookie()&quot;&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Browser Detection</title>
		<link>http://jaffnacampus.com/javascript/javascript-advanced/javascript-browser-detection/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-advanced/javascript-browser-detection/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:40:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Advanced]]></category>
		<category><![CDATA[JavaScript Browser Detection]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=267</guid>
		<description><![CDATA[The Navigator object contains information about the   visitor&#8217;s browser.

Browser Detection
Almost everything in this tutorial works on all JavaScript-enabled [...]]]></description>
			<content:encoded><![CDATA[<p>The Navigator object contains information about the   visitor&#8217;s browser.</p>
<hr />
<h2>Browser Detection</h2>
<p>Almost everything in this tutorial works on all JavaScript-enabled   browsers.   However, there are some things that just don&#8217;t work on certain browsers &#8211;   especially on older browsers.</p>
<p>So, sometimes it can be very useful to detect the visitor&#8217;s browser,   and then serve up the appropriate information.</p>
<p>The best way to do this is to make your web pages smart enough to   look one way to some browsers and another way to other browsers.</p>
<p>The Navigator object can be used for this purpose.</p>
<p>The Navigator object contains information about the visitor&#8217;s browser   name, version, and more.</p>
<p><strong>Note: There is no public standard that applies to the navigator object, but   all major browsers support it.</strong></p>
<hr />
<h2>The Navigator Object</h2>
<p>The Navigator object contains all information about the visitor&#8217;s   browser. We are going to look at two properties of the Navigator object:</p>
<ul>
<li>appName &#8211; holds the name of the browser</li>
<li>appVersion &#8211; holds, among other things, the version of the browser</li>
</ul>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;body&gt;</p>
<p>                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var browser=navigator.appName;<br />
                var b_version=navigator.appVersion;<br />
                var version=parseFloat(b_version);</p>
<p>                document.write(&quot;Browser name: &quot;+ browser);<br />
                document.write(&quot;&lt;br /&gt;&quot;);<br />
                document.write(&quot;Browser version: &quot;+ version);<br />
                &lt;/script&gt;</p>
<p>                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The variable &quot;browser&quot; in the example above holds the name of the   browser, i.e. &quot;Netscape&quot; or &quot;Microsoft Internet Explorer&quot;.</p>
<p>The appVersion property in the example above returns a string that   contains much more information than just the version number, but for now   we are only interested in the version   number. To pull the version number out of the string we are using a   function called parseFloat(), which pulls the first thing that looks   like a decimal number out of a string and returns it.</p>
<p><strong>IMPORTANT!</strong> The version number is WRONG in IE 5.0 or later!   Microsoft starts the appVersion string with the number 4.0. in IE 5.0   and IE 6.0!!! Why did they do that??? However, JavaScript is the same in   IE6, IE5 and IE4, so   for most scripts it is ok.</p>
<p>The example below displays a different alert, depending on the   visitor&#8217;s browser:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;html&gt;<br />
                &lt;head&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                function detectBrowser()<br />
                {<br />
                var browser=navigator.appName;<br />
                var b_version=navigator.appVersion;<br />
                var version=parseFloat(b_version);<br />
                if ((browser==&quot;Netscape&quot;||browser==&quot;Microsoft Internet Explorer&quot;)<br />
                &amp;&amp; (version&gt;=4))<br />
                {<br />
                alert(&quot;Your browser is good enough!&quot;);<br />
                }<br />
                else<br />
                {<br />
                alert(&quot;It&#8217;s time to upgrade your browser!&quot;);<br />
                }<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body onload=&quot;detectBrowser()&quot;&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-advanced/javascript-browser-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript RegExp Object</title>
		<link>http://jaffnacampus.com/javascript/javascript-object/javascript-regexp-object/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-object/javascript-regexp-object/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:38:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Object]]></category>
		<category><![CDATA[JavaScript RegExp Object]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=265</guid>
		<description><![CDATA[RegExp, is short for regular expression.

What is RegExp?
A regular expression is an object that describes a pattern of   [...]]]></description>
			<content:encoded><![CDATA[<p>RegExp, is short for regular expression.</p>
<hr />
<h2>What is RegExp?</h2>
<p>A regular expression is an object that describes a pattern of   characters.</p>
<p>When you search in a text, you can use a pattern to describe what you   are searching for.</p>
<p>A simple pattern can be one single character.</p>
<p>A more complicated pattern can consist of more characters, and can be   used for parsing, format checking, substitution and more.</p>
<p>Regular expressions are used to perform powerful pattern-matching and   &quot;search-and-replace&quot; functions on text.</p>
<h2>Syntax</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var txt=new RegExp(pattern,modifiers);</p>
<p>        or more simply:</p>
<p>        var txt=/pattern/modifiers; </td>
</tr>
</tbody>
</table>
<ul>
<li>pattern specifies the pattern of an expression</li>
<li>modifiers specify if a search should be global, case-sensitive,   etc.</li>
</ul>
<hr />
<h2>RegExp Modifiers</h2>
<p>Modifiers are used to perform case-insensitive and global searches.</p>
<p>The i modifier is used to perform case-insensitive matching.</p>
<p>The g modifier is used to perform a global match (find all matches   rather than stopping after the first match).</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example 1</h2>
<p>Do a case-insensitive search for &quot;w3schools&quot; in a string:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var str=&quot;Visit W3Schools&quot;;<br />
                var patt1=/w3schools/i; </td>
</tr>
</tbody>
</table>
<p>The marked text below shows where the   expression gets a match:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> Visit W3Schools </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example 2</h2>
<p>Do a global search for &quot;is&quot;:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var str=&quot;Is this all there is?&quot;;<br />
                var patt1=/is/g;</td>
</tr>
</tbody>
</table>
<p>The marked text below shows where the   expression gets a match:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> Is this all there is? </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example 3</h2>
<p>Do a global, case-insensitive search for &quot;is&quot;:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var str=&quot;Is this all there is?&quot;;<br />
                var patt1=/is/gi;</td>
</tr>
</tbody>
</table>
<p>The marked text below shows where the   expression gets a match:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> Is this all   there is? </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>test()</h2>
<p>The test() method searches a string for a specified value, and   returns true   or false, depending on the result.</p>
<p>The following example searches a string for the character &quot;e&quot;:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var patt1=new RegExp(&quot;e&quot;);<br />
                document.write(patt1.test(&quot;The best things   in life are free&quot;));</td>
</tr>
</tbody>
</table>
<p>Since there is an &quot;e&quot; in the string, the output of the code above   will be:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> true </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>exec()</h2>
<p>The exec() method searches a string for a specified value, and   returns the text of the found value. If no match is found, it returns <em>null.</em></p>
<p>The following example searches a string for the character &quot;e&quot;:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<h2>Example 1</h2>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var patt1=new RegExp(&quot;e&quot;);<br />
                document.write(patt1.exec(&quot;The best things   in life are free&quot;));</td>
</tr>
</tbody>
</table>
<p>Since there is an &quot;e&quot; in the string, the output of the code above   will be:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>e</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-object/javascript-regexp-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Math Object</title>
		<link>http://jaffnacampus.com/javascript/javascript-object/javascript-math-object/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-object/javascript-math-object/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:37:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Object]]></category>
		<category><![CDATA[JavaScript Math Object]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=263</guid>
		<description><![CDATA[The Math object allows you to perform mathematical   tasks.

Math Object
The Math object allows you to perform mathematical tasks.
The [...]]]></description>
			<content:encoded><![CDATA[<p>The Math object allows you to perform mathematical   tasks.</p>
<hr />
<h2>Math Object</h2>
<p>The Math object allows you to perform mathematical tasks.</p>
<p>The Math object includes several mathematical constants and methods.</p>
<p><strong>Syntax for using properties/methods of Math:</strong></p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var pi_value=Math.PI;<br />
        var sqrt_value=Math.sqrt(16);</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Math is not a constructor. All properties and methods of   Math can be called by using Math as an object without creating it.</p>
<hr />
<h2>Mathematical Constants</h2>
<p>JavaScript provides eight mathematical constants that can be accessed   from the Math object. These are: E, PI, square root of 2, square root   of 1/2, natural log of 2, natural log of 10, base-2 log of E, and   base-10 log of E.</p>
<p>You may reference these constants from your JavaScript like this:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> Math.E<br />
        Math.PI<br />
        Math.SQRT2<br />
        Math.SQRT1_2<br />
        Math.LN2<br />
        Math.LN10<br />
        Math.LOG2E<br />
        Math.LOG10E</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>Mathematical Methods</h2>
<p>In addition to the mathematical constants that can be accessed from   the Math object there are also several methods available.</p>
<p>The following example uses the round() method of the Math object to   round a number to the nearest integer:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>document.write(Math.round(4.7));</td>
</tr>
</tbody>
</table>
<p>The code above will result in the following output:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>5</td>
</tr>
</tbody>
</table>
<p>The following example uses the random() method of the Math object to   return a random number between 0 and 1:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>document.write(Math.random());</td>
</tr>
</tbody>
</table>
<p>The code above can result in the following output:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>document.write(Math.random())0.9673354658127411</td>
</tr>
</tbody>
</table>
<p>The following example uses the floor() and random() methods of the   Math object to return a random number between 0 and 10:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>document.write(Math.floor(Math.random()*11));</td>
</tr>
</tbody>
</table>
<p>The code above can result in the following output:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> document.write(Math.floor(Math.random()*11))6</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-object/javascript-math-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Boolean Object</title>
		<link>http://jaffnacampus.com/javascript/javascript-object/javascript-boolean-object/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-object/javascript-boolean-object/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:35:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Object]]></category>
		<category><![CDATA[JavaScript Boolean Object]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=261</guid>
		<description><![CDATA[The Boolean object is used to convert a non-Boolean   value to a Boolean value (true or false).

Create a [...]]]></description>
			<content:encoded><![CDATA[<p>The Boolean object is used to convert a non-Boolean   value to a Boolean value (true or false).</p>
<hr />
<h2>Create a Boolean Object</h2>
<p>The Boolean object represents two values: &quot;true&quot; or &quot;false&quot;.</p>
<p>The following code creates a Boolean object called myBoolean:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>var myBoolean=new Boolean();</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> If the Boolean object has no initial value or if it is   0, -0, null, &quot;&quot;, false, undefined,   or NaN, the object is set to false. Otherwise it is true (even with the   string &quot;false&quot;)!</p>
<p>All the following lines of code create Boolean objects with an   initial value of false:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var myBoolean=new Boolean();<br />
        var myBoolean=new Boolean(0);<br />
        var myBoolean=new Boolean(null);<br />
        var myBoolean=new Boolean(&quot;&quot;);<br />
        var myBoolean=new Boolean(false);<br />
        var myBoolean=new Boolean(NaN);</td>
</tr>
</tbody>
</table>
<p>And all the following lines of code create Boolean objects with an   initial value of true:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var myBoolean=new Boolean(true);<br />
        var myBoolean=new Boolean(&quot;true&quot;);<br />
        var myBoolean=new Boolean(&quot;false&quot;);<br />
        var myBoolean=new Boolean(&quot;Richard&quot;);</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-object/javascript-boolean-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

