<?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 Basic</title>
	<atom:link href="http://jaffnacampus.com/category/javascript/javascript-basic/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 Guidelines</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-guidelines/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-guidelines/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:07:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript Guidelines]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/javascript/javascript-basic/javascript-guidelines/</guid>
		<description><![CDATA[Some other important things to know when scripting with   JavaScript. 

JavaScript is Case Sensitive
A function named &#34;myfunction&#34; is not [...]]]></description>
			<content:encoded><![CDATA[<p>Some other important things to know when scripting with   JavaScript. </p>
<hr />
<h2>JavaScript is Case Sensitive</h2>
<p>A function named &quot;myfunction&quot; is not the same as &quot;myFunction&quot; and a   variable named &quot;myVar&quot; is not the same as  &quot;myvar&quot;.</p>
<p>JavaScript is case sensitive &#8211; therefore watch your capitalization   closely when you create or call variables, objects and functions.</p>
<hr />
<h2>White Space</h2>
<p>JavaScript ignores extra spaces. You can add white space to your   script to make it more readable. The following lines are equivalent:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> name=&quot;Hege&quot;;<br />
        name = &quot;Hege&quot;;</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>Break up a Code Line</h2>
<p>You can break up a code line <strong>within a text string</strong> with a   backslash. The example below will be displayed properly:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> document.write(&quot;Hello \<br />
        World!&quot;);</td>
</tr>
</tbody>
</table>
<p>However, you cannot break up a code line like this:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> document.write \<br />
        (&quot;Hello World!&quot;);</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-basic/javascript-guidelines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Special Characters</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-special-characters/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-special-characters/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:05:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript Special Characters]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=250</guid>
		<description><![CDATA[In JavaScript you can add special characters to a text   string by using the backslash sign.

Insert Special Characters
The [...]]]></description>
			<content:encoded><![CDATA[<p>In JavaScript you can add special characters to a text   string by using the backslash sign.</p>
<hr />
<h2>Insert Special Characters</h2>
<p>The backslash (\) is used to insert apostrophes, new lines, quotes,   and other special characters into a text string.</p>
<p>Look at the following JavaScript code:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var txt=&quot;We are the so-called &quot;Vikings&quot; from the north.&quot;;<br />
        document.write(txt);</td>
</tr>
</tbody>
</table>
<p>In JavaScript, a string is started and stopped with either single or   double quotes. This means that the string above will be chopped to: We   are the so-called</p>
<p>To solve this problem, you must place a backslash (\) before each   double quote in &quot;Viking&quot;. This turns each double quote into a string   literal:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> var txt=&quot;We are the so-called \&quot;Vikings\&quot; from the north.&quot;;<br />
        document.write(txt);</td>
</tr>
</tbody>
</table>
<p>JavaScript will now output the proper text string: We are the   so-called &quot;Vikings&quot; from the north.</p>
<p>Here is another example:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>document.write (&quot;You \&amp; I are singing!&quot;);</td>
</tr>
</tbody>
</table>
<p>The example above will produce the following output:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>You &amp; I are singing!</td>
</tr>
</tbody>
</table>
<p>The table below lists other special characters that can be added to a   text string with the backslash sign:</p>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left">Code</th>
<th align="left">Outputs</th>
</tr>
<tr>
<td>\&#8217;</td>
<td>single quote</td>
</tr>
<tr>
<td>\&quot;</td>
<td>double quote</td>
</tr>
<tr>
<td>\&amp;</td>
<td>ampersand</td>
</tr>
<tr>
<td>\\</td>
<td>backslash</td>
</tr>
<tr>
<td>\n</td>
<td>new line</td>
</tr>
<tr>
<td>\r</td>
<td>carriage return</td>
</tr>
<tr>
<td>\t</td>
<td>tab</td>
</tr>
<tr>
<td>\b</td>
<td>backspace</td>
</tr>
<tr>
<td>\f</td>
<td>form feed</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-basic/javascript-special-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Throw Statement</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-throw-statement/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-throw-statement/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:04:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript Throw Statement]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=248</guid>
		<description><![CDATA[The throw statement allows you to create an exception.

The Throw Statement
The throw statement allows you to create an exception. If [...]]]></description>
			<content:encoded><![CDATA[<p>The throw statement allows you to create an exception.</p>
<hr />
<h2>The Throw Statement</h2>
<p>The throw statement allows you to create an exception. If you use   this statement together with the try&#8230;catch statement, you can control   program   flow and generate accurate error messages.</p>
<h3>Syntax</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>throw(exception)</td>
</tr>
</tbody>
</table>
<p>The exception can be a string, integer, Boolean or an object.</p>
<p>Note that throw is written in lowercase letters. Using uppercase   letters will generate a JavaScript error!</p>
<h3>Example</h3>
<p>The example below determines the value of a variable called x. If the   value of x is higher than 10, lower than 0,   or not a number, we are going to throw an error.  The error is then caught by the catch argument and the proper error   message is displayed:</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;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var x=prompt(&quot;Enter a number between 0 and 10:&quot;,&quot;&quot;);<br />
                try<br />
                { <br />
                if(x&gt;10)<br />
                {<br />
                throw &quot;Err1&quot;;<br />
                }<br />
                else if(x&lt;0)<br />
                {<br />
                throw &quot;Err2&quot;;<br />
                }<br />
                else if(isNaN(x))<br />
                {<br />
                throw &quot;Err3&quot;;<br />
                }<br />
                }<br />
                catch(er)<br />
                {<br />
                if(er==&quot;Err1&quot;)<br />
                {<br />
                alert(&quot;Error! The value is too high&quot;);<br />
                }<br />
                if(er==&quot;Err2&quot;)<br />
                {<br />
                alert(&quot;Error! The value is too low&quot;);<br />
                }<br />
                if(er==&quot;Err3&quot;)<br />
                {<br />
                alert(&quot;Error! The value is not a number&quot;);<br />
                }<br />
                }<br />
                &lt;/script&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-basic/javascript-throw-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Try&#8230;Catch Statement</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-try-catch-statement/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-try-catch-statement/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:03:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript Try...Catch Statement]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=245</guid>
		<description><![CDATA[The try&#8230;catch statement allows you to test a block of   code   for errors.

JavaScript &#8211; Catching Errors
When [...]]]></description>
			<content:encoded><![CDATA[<p>The try&#8230;catch statement allows you to test a block of   code   for errors.</p>
<hr />
<h2>JavaScript &#8211; Catching Errors</h2>
<p>When browsing Web pages on the internet, we all have seen a   JavaScript alert box telling us there is a run time error and asking &quot;Do   you wish to debug?&quot;.   Error message like this may be useful for developers but not for users.   When users see errors, they often leave the Web page.</p>
<p>This chapter will teach you how to catch and handle JavaScript error   messages, so you don&#8217;t lose your audience.</p>
<hr />
<h2>The try&#8230;catch Statement</h2>
<p>The try&#8230;catch statement allows you to test a block of code for   errors. The try block contains the code to be run, and the catch block   contains the code to be   executed if an error occurs.</p>
<h3>Syntax</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> try<br />
        {<br />
        //Run some code here<br />
        }<br />
        catch(err)<br />
        {<br />
        //Handle errors here<br />
        }</td>
</tr>
</tbody>
</table>
<p>Note that try&#8230;catch is written in lowercase letters. Using   uppercase letters will generate a JavaScript error!</p>
<h2>Examples</h2>
<p>The example below is supposed to alert &quot;Welcome guest!&quot; when the   button is clicked. However, there&#8217;s a typo in the   message() function. alert() is misspelled as adddlert(). A JavaScript   error occurs. The catch block catches the error and executes a custom   code   to handle it. The code displays a custom error message informing the   user what happened:</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 txt=&quot;&quot;;<br />
                function message()<br />
                {<br />
                try<br />
                {<br />
                adddlert(&quot;Welcome guest!&quot;);<br />
                }<br />
                catch(err)<br />
                {<br />
                txt=&quot;There was an error on this page.\n\n&quot;;<br />
                txt+=&quot;Error description: &quot; + err.description + &quot;\n\n&quot;;<br />
                txt+=&quot;Click OK to continue.\n\n&quot;;<br />
                alert(txt);<br />
                }<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;input type=&quot;button&quot; value=&quot;View message&quot; onclick=&quot;message()&quot; /&gt;<br />
                &lt;/body&gt;</p>
<p>                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>The next example uses a confirm box to display a custom   message telling users they can click OK to continue viewing the page or   click   Cancel to go to the homepage. If the confirm method returns false, the   user   clicked Cancel, and the code redirects the user. If the confirm   method returns true, the code does nothing:</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 txt=&quot;&quot;;<br />
                function message()<br />
                {<br />
                try<br />
                {<br />
                adddlert(&quot;Welcome guest!&quot;);<br />
                }<br />
                catch(err)<br />
                {<br />
                txt=&quot;There was an error on this page.\n\n&quot;;<br />
                txt+=&quot;Click OK to continue viewing this page,\n&quot;;<br />
                txt+=&quot;or Cancel to return to the home page.\n\n&quot;;<br />
                if(!confirm(txt))<br />
                {<br />
                document.location.href=&quot;http://www.w3schools.com/&quot;;<br />
                }<br />
                }<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;input type=&quot;button&quot; value=&quot;View message&quot; onclick=&quot;message()&quot; /&gt;<br />
                &lt;/body&gt;</p>
<p>                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>The throw Statement</h2>
<p>The throw statement can be used together with the try&#8230;catch   statement, to   create an exception for the error. Learn about the throw statement in   the next   chapter.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-basic/javascript-try-catch-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Events</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-events/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-events/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 03:01:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript Events]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=243</guid>
		<description><![CDATA[Events are actions that can be detected by JavaScript.

Events
By using JavaScript, we have the ability to create dynamic web pages. [...]]]></description>
			<content:encoded><![CDATA[<p>Events are actions that can be detected by JavaScript.</p>
<hr />
<h2>Events</h2>
<p>By using JavaScript, we have the ability to create dynamic web pages.   Events are actions that can be detected by JavaScript.</p>
<p>Every element on a web page has certain events which can trigger a   JavaScript. For example, we can use the onClick event of a button   element to   indicate that a function will run when a user clicks on the button. We   define the events in the HTML tags.</p>
<p>Examples of events:</p>
<ul>
<li>A mouse click</li>
<li>A web page or an image loading</li>
<li>Mousing over a hot spot on the web page</li>
<li>Selecting an input field in an HTML form</li>
<li>Submitting an HTML form</li>
<li>A keystroke </li>
</ul>
<p><strong>Note:</strong> Events are normally used in combination with functions,   and the function will not be executed before the event occurs!</p>
<p>For a complete reference of the events recognized by JavaScript, go   to our   complete <a href="http://JaffnaCampus.com/javascript-referance">JavaScript   reference</a>.</p>
<hr />
<h2>onLoad and onUnload</h2>
<p>The onLoad and onUnload events are triggered when the user enters or   leaves the page.</p>
<p>The onLoad event is often used to check the visitor&#8217;s browser type   and browser version, and load the proper version of the web page based   on the information.</p>
<p>Both the onLoad and onUnload events are also often used to deal with   cookies that should be set when a user enters or leaves a page. For   example, you could have a popup asking   for the user&#8217;s name upon his first arrival to your page. The name is   then stored in a cookie. Next time the visitor arrives at your page,   you could have another popup saying something like: &quot;Welcome John Doe!&quot;.</p>
<hr />
<h2>onFocus, onBlur and onChange</h2>
<p>The onFocus, onBlur and onChange events are often used in combination   with validation of form fields.</p>
<p>Below is an example of how to use the onChange event. The   checkEmail() function will be called whenever the user changes the   content of the field:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;input type=&quot;text&quot; size=&quot;30&quot; id=&quot;email&quot;   onchange=&quot;checkEmail()&quot;&gt;</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>onSubmit</h2>
<p>The onSubmit event is used to validate ALL form fields before   submitting it.</p>
<p>Below is an example of how to use the onSubmit event. The checkForm()   function will be called when the user clicks the submit button in the   form. If the   field values are not accepted, the submit should be cancelled. The   function checkForm() returns either true or false. If it returns true   the   form will be submitted, otherwise the submit will be cancelled:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;form method=&quot;post&quot; action=&quot;xxx.htm&quot; onsubmit=&quot;return   checkForm()&quot;&gt;</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>onMouseOver and onMouseOut</h2>
<p>onMouseOver and onMouseOut are often used to create &quot;animated&quot;   buttons.</p>
<p>Below is an example of an onMouseOver event. An alert box appears   when an onMouseOver event is detected:</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>&lt;a href=&quot;http://www.w3schools.com&quot;  onmouseover=&quot;alert(&#8216;An onMouseOver event&#8217;);return false&quot;&gt;&lt;img   src=&quot;w3s.gif&quot;   alt=&quot;W3Schools&quot; /&gt;&lt;/a&gt;</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-basic/javascript-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript For&#8230;In Statement</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-for-in-statement/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-for-in-statement/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 02:58:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript For...In Statement]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=241</guid>
		<description><![CDATA[JavaScript For&#8230;In Statement
The for&#8230;in statement loops through the elements of an array or   through the properties of an [...]]]></description>
			<content:encoded><![CDATA[<h2>JavaScript For&#8230;In Statement</h2>
<p>The for&#8230;in statement loops through the elements of an array or   through the properties of an object.</p>
<h3>Syntax</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>for (<em>variable</em> in <em>object</em>)<br />
        {<br />
        <em>  code to be executed</em><br />
        }</td>
</tr>
</tbody>
</table>
<p><strong>Note: </strong>The code in the body of the for&#8230;in loop is executed   once for each element/property.</p>
<p><strong>Note: </strong>The variable argument can be a named variable, an array   element, or a property of an object.</p>
<h3>Example</h3>
<p>Use the for&#8230;in statement to loop through an array:</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;body&gt;</p>
<p>                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var x;<br />
                var mycars = new Array();<br />
                mycars[0] = &quot;Saab&quot;;<br />
                mycars[1] = &quot;Volvo&quot;;<br />
                mycars[2] = &quot;BMW&quot;;</p>
<p>                for (x in mycars)<br />
                {<br />
                document.write(mycars[x] + &quot;&lt;br /&gt;&quot;);<br />
                }<br />
                &lt;/script&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-basic/javascript-for-in-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Break and Continue Statements</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-break-and-continue-statements/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-break-and-continue-statements/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 02:57:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[Continue Statements]]></category>
		<category><![CDATA[JavaScript Break]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=239</guid>
		<description><![CDATA[The break Statement
The break statement will break the loop and continue executing the   code that follows after the [...]]]></description>
			<content:encoded><![CDATA[<h2>The break Statement</h2>
<p>The break statement will break the loop and continue executing the   code that follows after the loop (if any).</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;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var i=0;<br />
                for (i=0;i&lt;=10;i++)<br />
                {<br />
                if (i==3)<br />
                {<br />
                break;<br />
                }<br />
                document.write(&quot;The number is &quot; + i);<br />
                document.write(&quot;&lt;br /&gt;&quot;);<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>The continue Statement</h2>
<p>The continue statement will break the current loop and continue with   the next value.</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;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var i=0<br />
                for (i=0;i&lt;=10;i++)<br />
                {<br />
                if (i==3)<br />
                {<br />
                continue;<br />
                }<br />
                document.write(&quot;The number is &quot; + i);<br />
                document.write(&quot;&lt;br /&gt;&quot;);<br />
                }<br />
                &lt;/script&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-basic/javascript-break-and-continue-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript While Loop</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-while-loop/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-while-loop/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 02:55:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript While Loop]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=237</guid>
		<description><![CDATA[Loops execute a block of code  a specified number of times, or while a specified condition is true.

The while [...]]]></description>
			<content:encoded><![CDATA[<p>Loops execute a block of code  a specified number of times, or while a specified condition is true.</p>
<hr />
<h2>The while Loop</h2>
<p>The while loop loops through a block of code while a specified   condition is true.</p>
<h3>Syntax</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> while (var&lt;=endvalue)<br />
        {<br />
        <em>  code to be executed</em><br />
        }</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The &lt;= could be any comparing statement.</p>
<h3>Example</h3>
<p>The example below defines a loop that starts with i=0. The loop   will continue to run as long as <strong>i</strong> is less than, or equal to 5. <strong>i</strong> will increase by 1 each time the loop runs:</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;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var i=0;<br />
                while (i&lt;=5)<br />
                {<br />
                document.write(&quot;The number is &quot; + i);<br />
                document.write(&quot;&lt;br /&gt;&quot;);<br />
                i++;<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>The do&#8230;while Loop</h2>
<p>The do&#8230;while loop is a variant of the while loop. This loop will   execute the block of code ONCE, and then it will  repeat the loop as long as the specified condition is true.</p>
<h3>Syntax</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> do<br />
        {<br />
        <em>  code to be executed<br />
        </em>}<br />
        while (var&lt;=endvalue);</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<p>The example below uses a do&#8230;while loop. The do&#8230;while loop will   always be   executed at least once, even if the condition is false, because the   statements   are executed before the condition is tested:</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;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var i=0;<br />
                do<br />
                {<br />
                document.write(&quot;The number is &quot; + i);<br />
                document.write(&quot;&lt;br /&gt;&quot;);<br />
                i++;<br />
                }<br />
                while (i&lt;=5);<br />
                &lt;/script&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-basic/javascript-while-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript For Loop</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-for-loop/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-for-loop/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 02:54:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript For Loop]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=235</guid>
		<description><![CDATA[Loops execute a block of code  a specified number of times, or while a specified condition is true.

JavaScript Loops
Often [...]]]></description>
			<content:encoded><![CDATA[<p>Loops execute a block of code  a specified number of times, or while a specified condition is true.</p>
<hr />
<h2>JavaScript Loops</h2>
<p>Often when you write code, you want the same block of code to run   over and over again in a row.  Instead of adding several almost equal lines in a script we can use   loops to perform a task like this.</p>
<p>In JavaScript, there are two different kind of loops:</p>
<ul>
<li><strong>for </strong>- loops through a block of code a specified number of   times</li>
<li><strong>while </strong>- loops through a block of code while a specified   condition is true</li>
</ul>
<hr />
<h2>The for Loop</h2>
<p>The for loop is used when you know in advance how many times the   script should run.</p>
<h3><strong>Syntax</strong></h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> for (var=startvalue;var&lt;=endvalue;var=var+increment)<br />
        {<br />
        <em>code to be executed</em><br />
        }</td>
</tr>
</tbody>
</table>
<h3><strong>Example</strong></h3>
<p>The example below defines a loop that starts with i=0. The loop will   continue to run as long as <strong>i</strong> is less than, or equal to   5. <strong>i</strong> will increase by 1 each time the loop runs.</p>
<p><strong>Note:</strong> The increment parameter could also be negative, and the   &lt;= could be any comparing statement.</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;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                var i=0;<br />
                for (i=0;i&lt;=5;i++)<br />
                {<br />
                document.write(&quot;The number is &quot; + i);<br />
                document.write(&quot;&lt;br /&gt;&quot;);<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>The while loop</h2>
<p>The while loop will be explained in the next chapter.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-basic/javascript-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Functions</title>
		<link>http://jaffnacampus.com/javascript/javascript-basic/javascript-functions/</link>
		<comments>http://jaffnacampus.com/javascript/javascript-basic/javascript-functions/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 02:52:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Basic]]></category>
		<category><![CDATA[JavaScript Functions]]></category>

		<guid isPermaLink="false">http://jaffnacampus.com/?p=233</guid>
		<description><![CDATA[A function will be executed by an event or by a call to   the function.

JavaScript Functions
To keep the [...]]]></description>
			<content:encoded><![CDATA[<p>A function will be executed by an event or by a call to   the function.</p>
<hr />
<h2>JavaScript Functions</h2>
<p>To keep the browser from executing a script when the page loads, you   can put your script into a function.</p>
<p>A function contains code that will be executed by an event or by a   call to the function.</p>
<p>You may call a function from anywhere within a page (or even from   other pages if the function is embedded in an external .js file).</p>
<p>Functions can be defined both in the &lt;head&gt; and in the   &lt;body&gt; section of a document. However, to assure that a function  is read/loaded by the browser before it is called, it could be wise to   put functions in the &lt;head&gt; section.</p>
<hr />
<h2>How to Define a Function</h2>
<h3>Syntax</h3>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td> function <em>functionname</em>(<em>var1,var2,&#8230;,varX</em>)<br />
        {<br />
        <em>some code</em><br />
        }</td>
</tr>
</tbody>
</table>
<p>The parameters var1, var2, etc. are variables or values passed into   the function. The { and the } defines the start and end of the function.</p>
<p><strong>Note:</strong> A function with no parameters must include the   parentheses ()   after the function name.</p>
<p><strong>Note:</strong> Do not forget about the importance of capitals in   JavaScript!   The word function must be written in lowercase letters, otherwise a   JavaScript   error occurs! Also note that you must call a function with the exact   same   capitals as in the function name.
</p>
<hr />
<h2>JavaScript Function Example</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 displaymessage()<br />
                {<br />
                alert(&quot;Hello World!&quot;);<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;Click me!&quot;  onclick=&quot;displaymessage()&quot; /&gt;<br />
                &lt;/form&gt;<br />
                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>If the line: alert(&quot;Hello world!!&quot;) in the example above had not been   put   within a function, it would have been executed as soon as the line was   loaded.   Now, the script is not executed before a user hits the input button. The   function displaymessage()   will be executed if the input button is clicked.</p>
<p>You will learn more about JavaScript events in the JS Events chapter.</p>
<hr />
<h2>The return Statement</h2>
<p>The return statement is used to specify the value that is returned   from the function.</p>
<p>So, functions that are going to return a value must use the return   statement.</p>
<p>The example below returns the product of two numbers (a and b):</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 product(a,b)<br />
                {<br />
                return a*b;<br />
                }<br />
                &lt;/script&gt;<br />
                &lt;/head&gt;</p>
<p>                &lt;body&gt;<br />
                &lt;script type=&quot;text/javascript&quot;&gt;<br />
                document.write(product(4,3));<br />
                &lt;/script&gt;</p>
<p>                &lt;/body&gt;<br />
                &lt;/html&gt;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p></p>
<hr />
<h2>The Lifetime of JavaScript Variables</h2>
<p>If you declare a variable within a function, the variable can only be   accessed within that function. When you exit the function, the  variable is destroyed. These variables are called local variables. You   can have local variables with the same name in different functions,   because each is  recognized only by the function in which it is declared.</p>
<p>If you declare a variable outside a function, all the functions on   your page can access it. The lifetime of these variables starts when   they are declared, and  ends when the page is closed.</p>
]]></content:encoded>
			<wfw:commentRss>http://jaffnacampus.com/javascript/javascript-basic/javascript-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

