<?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>Web Design Blog &#124; Web Design Fan &#124; Resources for Web Designers and Graphic Designers &#187; Coding</title>
	<atom:link href="http://webdesignfan.com/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdesignfan.com</link>
	<description>Web Design Fan is a blog focused on the beautiful and interesting world of web design and development. We post tutorials, review web tools and services, give away graphics, and deliver all of the information web designers need the most.</description>
	<lastBuildDate>Tue, 07 Feb 2012 21:36:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Must See: Famous Logos and Icons in Pure CSS</title>
		<link>http://webdesignfan.com/must-see-famous-logos-and-icons-in-pure-css/</link>
		<comments>http://webdesignfan.com/must-see-famous-logos-and-icons-in-pure-css/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 16:42:19 +0000</pubDate>
		<dc:creator>Zachary Brown</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Icons]]></category>
		<category><![CDATA[logos]]></category>

		<guid isPermaLink="false">http://webdesignfan.com/?p=8748</guid>
		<description><![CDATA[There are some incredible things happening with CSS these days, and I think I found my favorite. 

Cool things are happening over at <a href="http://www.ecsspert.com/">ECSSpert</a>. So far they have reproduced pure CSS logos for <a href="http://www.ecsspert.com/twitter.php">Twitter</a>, <a href="http://www.ecsspert.com/adidas-originals.php">Adidas</a>, <a href="http://www.ecsspert.com/adobe.php">Adobe</a>, an awesome animated <a href="http://www.ecsspert.com/atari.php">Atari</a>, and well... <a href="http://www.ecsspert.com/">just go look for yourselves</a>. More after the jump.]]></description>
			<content:encoded><![CDATA[<p>There are some incredible things happening with CSS these days, and I think I found my favorite. Check it out:</p>
<p><img class="alignnone size-full wp-image-8757" title="pepsi" src="http://webdesignfan.com/wp-content/uploads/2011/10/pepsi.png" alt="pepsi " width="354" height="284" /></p>
<p>And this one:</p>
<p><img class="alignnone size-full wp-image-8758" title="windows" src="http://webdesignfan.com/wp-content/uploads/2011/10/windows.png" alt="windows " width="423" height="264" /></p>
<p>These awesome logos (along with tons of others. See: the post thumbnail) are being created in pure CSS over at <a href="http://www.ecsspert.com/">ECSSpert</a>. So far there are designs for <a href="http://www.ecsspert.com/twitter.php">Twitter</a>, <a href="http://www.ecsspert.com/adidas-originals.php">Adidas</a>, <a href="http://www.ecsspert.com/adobe.php">Adobe</a>, an awesome animated <a href="http://www.ecsspert.com/atari.php">Atari</a>, and well&#8230; <a href="http://www.ecsspert.com/">just go look for yourselves</a>.</p>
<p>Speaking of increible CSS achievements, check out these 3 links to be in even further awe:</p>
<p><a href="http://graphicpeel.com/cssiosicons">Apple iOS Icons in CSS</a></p>
<p><a href="http://lab.jeffbatterton.com/iphone-css3/">iPhone in CSS</a></p>
<p><a href="http://desandro.com/articles/opera-logo-css/">Opera Logo in CSS</a></p>
<p>Note: you might want to view these using Safari or Chrome, though Firefox is OK, too. Don&#8217;t even bother if you are using IE. Sorry, IE peeps (though you were probably just going to go look at the Windows icon and leave, anyway).</p>
<h3>Got any others?</h3>
<p>Post them in the comments so everyone can see. No use in keeping incredible stuff like this under wraps!
<div class="shr-publisher-8748"></div>
]]></content:encoded>
			<wfw:commentRss>http://webdesignfan.com/must-see-famous-logos-and-icons-in-pure-css/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>20 Great Uses of HTML5 Techniques</title>
		<link>http://webdesignfan.com/20-great-uses-of-html5-techniques/</link>
		<comments>http://webdesignfan.com/20-great-uses-of-html5-techniques/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 20:51:39 +0000</pubDate>
		<dc:creator>Yanuar Prisantoso</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://webdesignfan.com/?p=8454</guid>
		<description><![CDATA[As one application programming, HTML5 is widely used in some platforms script based. One of the functions that can be optimized is the use of the HTML5 web design to application development. Some of the techniques that you can try are to do some modification of the script code from a web design. With HTML5 and application of existing techniques, you can make some changes, including doing a combination of techniques HTML5 with j-Query. If you are interested in trying some of the existing functionality, is currently a lot of tutorials that can be alternatives, including how to use the HTML5 technique that suits as your needs.]]></description>
			<content:encoded><![CDATA[<p>As one application programming, HTML5 is widely used in some platforms script based. One of the functions that can be optimized is the use of the HTML5 web design to application development. Some of the techniques that you can try are to do some modification of the script code from a web design. With HTML5 and application of existing techniques, you can make some changes, including doing a combination of techniques HTML5 with j-Query. If you are interested in trying some of the existing functionality, is currently a lot of tutorials that can be alternatives, including how to use the HTML5 technique that suits as your needs.</p>
<h2><a href="http://slides.html5rocks.com/#title-slide">Rocking HTML5</a></h2>
<p><img class="alignnone size-full wp-image-8519" src="http://webdesignfan.com/wp-content/uploads/2011/09/title-slide1.jpg" alt="title slide1 " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>This presentation use HTML5 techniques to create a very informative and easy to use overview of the HTML5 elements.</p>
<h2><a href="http://www.html5test.com/">HTML5test</a></h2>
<p><img class="alignnone size-full wp-image-8521" src="http://webdesignfan.com/wp-content/uploads/2011/09/html5test1.jpg" alt="html5test1 " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>HTML5 test score is an indication of how well your browser supports the upcoming HTML5 standard and related specifications. The HTML5 test does not try to test all of the new features offered by HTML5, nor does it try to test the functionality of each feature it does detect.</p>
<h2><a href="http://hakim.se/experiments/html5/wave/03/">Wave Motion</a></h2>
<p><img class="alignnone size-full wp-image-8525" src="http://webdesignfan.com/wp-content/uploads/2011/09/wave1.jpg" alt="wave1 " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>This experiment, made by Hakim el Hattab, makes a wave motion rendered using the canvas element. Each bubble holds a tweet with the word water in it. Clicking on them we can read the tweets.</p>
<h2><a href="http://www.useragentman.com/blog/2010/01/10/cross-browser-html5-drag-and-drop/">Cross Browser HTML5 Drag and Drop</a></h2>
<p><img class="alignnone size-full wp-image-8524" src="http://webdesignfan.com/wp-content/uploads/2011/09/dragAndDrop2.jpg" alt="dragAndDrop2 " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>In order to save other developers from the headaches we got deciphering cross browser drag and drop, here are the following guide that shows how to do in five easy steps.</p>
<h2><a href="http://mrdoob.com/projects/chromeexperiments/ball_pool/">Ball Pool</a></h2>
<p><img class="alignnone size-full wp-image-8527" src="http://webdesignfan.com/wp-content/uploads/2011/09/dragball.jpg" alt="dragball " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>This is a great example of canvas using. This script use the mouse click and mouse drag for moving or creating other balls into the page.</p>
<h2><a href="http://experiments.instrum3nt.com/markmahoney/ball/">Browser Ball</a></h2>
<p><img class="alignnone size-full wp-image-8528" src="http://webdesignfan.com/wp-content/uploads/2011/09/ball.jpg" alt="ball " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>The main window should also have a beach ball. Fling that puppy around. Make neat spaces for the ball to bounce around in. Create complicated layouts that may crash your browser.</p>
<h2><a href="http://andrew-hoyer.com/experiments/cloth/">The Cloth Simulation</a></h2>
<p><img class="alignnone size-full wp-image-8529" src="http://webdesignfan.com/wp-content/uploads/2011/09/cloud.jpg" alt="cloud " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>The cloth is really then just a collection of constraints and point masses in a never ending struggle.</p>
<h2><a href="http://www.craftymind.com/2010/04/20/blowing-up-html5-video-and-mapping-it-into-3d-space/">Blowing up HTML5 Video and Mapping it into 3D space</a></h2>
<p><img class="alignnone size-full wp-image-8530" src="http://webdesignfan.com/wp-content/uploads/2011/09/html5boom.jpg" alt="html5boom " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>The API lets you take the contents of specific HTML elements and draw them into a canvas, and the 3rd element in that list is just begging to be abused. Copying video into a canvas element means opening up the ability to manipulate or process video frames at runtime. Two concepts instantly came to mind that seemed like fun to try and figure out, here they are below.</p>
<h2><a href="http://net.tutsplus.com/tutorials/html-css-techniques/quick-tip-learning-about-html5-local-storage/">Learning About HTML5 Local Storage</a></h2>
<p><img class="alignnone size-full wp-image-8548" src="http://webdesignfan.com/wp-content/uploads/2011/09/learning.jpg" alt="learning " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>This video tutorial shows how to build a simple to-do list with <em>local storage</em>. HTML5′s local storage is a new functionality which we can save data in browsers even the browser is refreshed or closed.</p>
<h2><a href="http://aduros.emufarmers.com/easel/">Tetris With HTML5</a></h2>
<p><img class="alignnone size-full wp-image-8532" src="http://webdesignfan.com/wp-content/uploads/2011/09/tetris.jpg" alt="tetris " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>Now we can play at this game online with the experiment of Bruno Garcia developed using HTML5′s Canvas.</p>
<h2><a href="http://camendesign.com/code/video_for_everybody">Video for Everybody</a></h2>
<p><img class="alignnone size-full wp-image-8533" src="http://webdesignfan.com/wp-content/uploads/2011/09/video.jpg" alt="video " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>This is a simply chunk of HTML code that embeds a video into a website using the HTML5 &lt;video&gt; element. It works on many browser and platforms.</p>
<h2><a href="http://tutorialzine.com/2010/02/html5-css3-website-template/">One Page Website Template</a></h2>
<p><img class="alignnone size-full wp-image-8537" src="http://webdesignfan.com/wp-content/uploads/2011/09/one-page2.jpg" alt="one page2 " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>Single-page websites have been commonplace on the web for a few years now. First made popular by designers seeking a clean, simple way to showcase portfolios, the one-page website now has a number of uses, including advertising software and promoting events. It’s a great way to have a large impact with a small amount of content.</p>
<h2><a href="http://blog.cballenar.com/2010/05/hybrid-column-layout/">Hybrid Column Layout</a></h2>
<p><img class="alignnone size-full wp-image-8539" src="http://webdesignfan.com/wp-content/uploads/2011/09/hybrid.jpg" alt="hybrid " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>You can easy to make website with liquid columns that use percentage.</p>
<h2><a href="http://line25.com/tutorials/design-and-code-a-cool-iphone-app-website-in-html5">Design &amp; Code a Cool iPhone App Website in HTML5</a></h2>
<p><img class="alignnone size-full wp-image-8540" src="http://webdesignfan.com/wp-content/uploads/2011/09/iphone.jpg" alt="iphone " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>HTML5 is definitely the flavor of the month, with everyone in the design community getting excited about its release. In this tutorial we’ll get a taste of what’s to come by building a cool iPhone app website using a HTML5 structure, and visual styling with some CSS3 effects.</p>
<h2><a href="http://sixrevisions.com/web-development/html5-iphone-app/">Create an HTML5 iPhone App</a></h2>
<p><img class="alignnone size-full wp-image-8546" src="http://webdesignfan.com/wp-content/uploads/2011/09/iphone-app.jpg" alt="iphone app " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>You can create a native app that lives with all the other apps, and for the most part, it’s going to be a pitch-perfect imitation. You can do this with the skill set you probably already have: HTML(5), CSS, and JavaScript.</p>
<h2><a href="http://24ways.org/2009/have-a-field-day-with-html5-forms">Have a Field Day with HTML5 Forms</a></h2>
<p><img class="alignnone size-full wp-image-8542" src="http://webdesignfan.com/wp-content/uploads/2011/09/24ways.jpg" alt="24ways " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>Here we’re going to take a look at how to style a beautiful HTML5 form using some advanced CSS and latest CSS3 techniques.</p>
<h2><a href="http://sixrevisions.com/html/canvas-element/">HTML5 Canvas Element Guide</a></h2>
<p><img class="alignnone size-full wp-image-8545" src="http://webdesignfan.com/wp-content/uploads/2011/09/canvas.jpg" alt="canvas " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>In this guide, you can get started to understanding the canvas element and what kinds of things are required and expected in this associated code.</p>
<h2><a href="http://canvaspaint.org/">Canvas Paint</a></h2>
<p><img class="alignnone size-full wp-image-8544" src="http://webdesignfan.com/wp-content/uploads/2011/09/paint.jpg" alt="paint " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>CanvasPaint is a near pixel-perfect copy of Microsoft Paint in HTML, CSS and JavaScript, using the <code>&lt;canvas&gt;</code> tag.</p>
<h2><a href="http://peterned.home.xs4all.nl/3d/">Canvas in 3D</a></h2>
<p><img class="alignnone size-full wp-image-8543" src="http://webdesignfan.com/wp-content/uploads/2011/09/3d.jpg" alt="3d " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>In this script we will see an amazing 3D interface with random Flickr photos loaded by clicking on surface.</p>
<h2><a title="detect HTML5" href="http://diveintohtml5.org/detect.html" target="_blank">Detecting HTML5 Features</a></h2>
<p><img class="alignnone size-full wp-image-8550" src="http://webdesignfan.com/wp-content/uploads/2011/09/detect.jpg" alt="detect " width="550" height="324" title="20 Great Uses of HTML5 Techniques" /></p>
<p>Sometime HTML5, cannot running well on several browsers. As we know, not all  browsers  support html5 features.  this information will let you know about how to Detecting HTML5 Features
<div class="shr-publisher-8454"></div>
]]></content:encoded>
			<wfw:commentRss>http://webdesignfan.com/20-great-uses-of-html5-techniques/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Integrating Datepicker with jQuery</title>
		<link>http://webdesignfan.com/integrating-datepicker-with-jquery/</link>
		<comments>http://webdesignfan.com/integrating-datepicker-with-jquery/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 18:12:52 +0000</pubDate>
		<dc:creator>Pratima Paliwal</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://webdesignfan.com/?p=8371</guid>
		<description><![CDATA[<p>Gone are the days when we have to write code, manually from scratch, to create a Website in an editor, mostly it was Notepad. Nowadays, we are using tools like Adobe Dreamweaver, Zend Studio, Microsoft Visual Studio Express and existing code libraries to simplify our work and get it done with fewer efforts in less time.</p> <p>Today, we will discuss about one such code library named jQuery. It is an open source, is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. In this write up, we will show how you can create a Datepicker using this jQuery library.</p> <p>You can download the source files used in the end of the article.</p>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"></script>Gone are the days when we have to write code, manually from scratch, to create a Website in an editor, mostly it was Notepad. Nowadays, we are using tools like Adobe Dreamweaver, Zend Studio, Microsoft Visual Studio Express and existing code libraries to simplify our work and get it done with fewer efforts in less time. Today, we will discuss about one such code library named jQuery. It is an open source, is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. In this write up, we will show how you can create a Datepicker using this jQuery library. You can download the source files used in the end of the article.</p>
<h3>Adding Default Datepicker</h3>
<h3>Step 1</h3>
<p>Create a standard HTML file first.</p>
<h3>Step 2</h3>
<p>You should link the default datepicker JS and CSS files within the &lt;head&gt; section of your HTML file. You can download these files at the end of this article. Here is the code:</p>
<pre class="html"><span class="htmlOtherTag">&lt;link rel=<span class="htmlAttributeValue">&quot;stylesheet&quot;</span> typePreview post=<span class="htmlAttributeValue">&quot;text/css&quot;</span> href=<span class="htmlAttributeValue">&quot;demos.css&quot;</span>&gt;</span>

<span class="htmlOtherTag">&lt;link rel=<span class="htmlAttributeValue">&quot;stylesheet&quot;</span> type=<span class="htmlAttributeValue">&quot;text/css&quot;</span> href=<span class="htmlAttributeValue">&quot;jquery-ui.css&quot;</span>&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery-1.5.1.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery.ui.core.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery.ui.widget.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery.ui.datepicker.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span></pre>
<p>You can customize the demo.css file to change the layout and positioning of datepicker. In addition, you can extract the CSS code used in the HTML from it and add it within style tag for integrating the datepicker in your Website. We suggest you not play with the jquery-ui.css file as it is a member of jQuery libraries and Google AJAX APIs.</p>
<h3>Step 3</h3>
<p>Now, you have to add a container in the body tag to create the datepicker. Following is the code for it:</p>
<pre class="html"><span class="htmlOtherTag">&lt;div&gt;</span>

<span class="htmlOtherTag">&lt;p&gt;</span>Select the date: <span class="htmlFormTag">&lt;input type=<span class="htmlAttributeValue">&quot;text&quot;</span>&gt;</span><span class="htmlOtherTag">&lt;/p&gt;</span>

<span class="htmlOtherTag">&lt;/div&gt;</span></pre>
<p>The scripts mentioned in above JS file works automatically and adds the datepicker in the input box created. When a user clicks the box, the datepicker will appear.</p>
<h3>Complete Code of default datepicker</h3>
<pre class="html"><span class="htmlOtherTag">&lt;html&gt;</span>

<span class="htmlOtherTag">&lt;head&gt;</span>

<span class="htmlOtherTag">&lt;title&gt;</span>Default jQuery Datepicker<span class="htmlOtherTag">&lt;/title&gt;</span>

<span class="htmlOtherTag">&lt;link rel=<span class="htmlAttributeValue">&quot;stylesheet&quot;</span> type=<span class="htmlAttributeValue">&quot;text/css&quot;</span> href=<span class="htmlAttributeValue">&quot;demos.css&quot;</span>&gt;</span>

<span class="htmlOtherTag">&lt;link rel=<span class="htmlAttributeValue">&quot;stylesheet&quot;</span> type=<span class="htmlAttributeValue">&quot;text/css&quot;</span> href=<span class="htmlAttributeValue">&quot;jquery-ui.css&quot;</span>&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery-1.5.1.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery.ui.core.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery.ui.widget.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script src=<span class="htmlAttributeValue">&quot;jquery.ui.datepicker.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlScriptTag">&lt;script&gt;</span>

$(function() {

$( &quot;#datepicker&quot; ).datepicker();

});

<span class="htmlScriptTag">&lt;/script&gt;</span>

<span class="htmlOtherTag">&lt;/head&gt;</span>

<span class="htmlOtherTag">&lt;body&gt;</span>

<span class="htmlOtherTag">&lt;div style=<span class="htmlAttributeValue">&quot;<span class="cssProperty">width</span><span class="cssRest">:</span><span class="cssValue">500px</span><span class="cssRest">;</span> <span class="cssProperty">height</span><span class="cssRest">:</span><span class="cssValue">auto</span><span class="cssRest">;</span> <span class="cssProperty">font-size</span><span class="cssRest">:</span><span class="cssValue">small</span><span class="cssRest">;</span>&quot;</span>&gt;</span>

<span class="htmlOtherTag">&lt;div class=<span class="htmlAttributeValue">&quot;demo&quot;</span>&gt;</span>

<span class="htmlOtherTag">&lt;p&gt;</span>Select the date: <span class="htmlFormTag">&lt;input type=<span class="htmlAttributeValue">&quot;text&quot;</span>&gt;</span><span class="htmlOtherTag">&lt;/p&gt;</span>

<span class="htmlOtherTag">&lt;/div&gt;</span>

<span class="htmlOtherTag">&lt;/div&gt;</span>

<span class="htmlOtherTag">&lt;/body&gt;</span>

<span class="htmlOtherTag">&lt;/html&gt;</span></pre>
<h3>Output</h3>
<p>Following is a screenshot of the output:</p>
<p><a href="http://webdesignfan.com/wp-content/uploads/2011/08/screenshot-of-default-jquery-datepicker.jpg"><img class="alignnone size-full wp-image-8378" title="screenshot of default jquery datepicker" src="http://webdesignfan.com/wp-content/uploads/2011/08/screenshot-of-default-jquery-datepicker.jpg" alt="screenshot of default jquery datepicker " width="298" height="178" /></a></p>
<p><em>Screenshot of default jQuery datepicker</em></p>
<h3>Date Format Options</h3>
<p>In the default jQuery datepicker, the date is displayed in the default format MM/DD/YYYY after selecting any date. jQuery allows you modifying the date format. Let us have a look how to customize the date format for datepicker.</p>
<h3>Step 1</h3>
<p>Change the default script code with this one:</p>
<pre class="javascript">&lt;script&gt;

$(function() {

$( "#datepicker" ).datepicker();

$( "#format" ).change(function() {

$("#datepicker").datepicker( "option", "dateFormat", $( this ).val() );

});

});

&lt;/script&gt;</pre>
<p>The jQuery provides following date formats:</p>
<ol>
<li>mm/dd/yy     like  06/12/10</li>
<li>yy-mm-dd     like  10-06-12</li>
<li>d M, y      like  6 Jun, 10</li>
<li>d MM, y    like  6 June, 10</li>
<li>DD, d MM, yy    like  Sunday, 6 June, 2010</li>
<li>&#8216;day&#8217; d &#8216;of&#8217; MM &#8216;in the year&#8217; yy  like day 6 of June in the year 2010</li>
</ol>
<h3>Step 2</h3>
<p>Add the follow code in the HTML below the div demo code:</p>
<pre class="html"><span class="htmlOtherTag">&lt;p&gt;</span>Select the format to display date:

<span class="htmlFormTag">&lt;select&gt;</span>

<span class="htmlFormTag">&lt;option value=<span class="htmlAttributeValue">&quot;mm/dd/yy&quot;</span>&gt;</span>Default - mm/dd/yy<span class="htmlFormTag">&lt;/option&gt;</span>

<span class="htmlFormTag">&lt;option value=<span class="htmlAttributeValue">&quot;yy-mm-dd&quot;</span>&gt;</span>ISO 8601 - yy-mm-dd<span class="htmlFormTag">&lt;/option&gt;</span>

<span class="htmlFormTag">&lt;option value=<span class="htmlAttributeValue">&quot;d M, y&quot;</span>&gt;</span>Short - d M, y<span class="htmlFormTag">&lt;/option&gt;</span>

<span class="htmlFormTag">&lt;option value=<span class="htmlAttributeValue">&quot;d MM, y&quot;</span>&gt;</span>Medium - d MM, y<span class="htmlFormTag">&lt;/option&gt;</span>

<span class="htmlFormTag">&lt;option value=<span class="htmlAttributeValue">&quot;DD, d MM, yy&quot;</span>&gt;</span>Full - DD, d MM, yy<span class="htmlFormTag">&lt;/option&gt;</span>

<span class="htmlFormTag">&lt;option value=<span class="htmlAttributeValue">&quot;&#039;day&#039; d &#039;of&#039; MM &#039;in the year&#039; yy&quot;</span>&gt;</span>With text - &#039;day&#039; d &#039;of&#039; MM &#039;in the ye ar&#039; yy<span class="htmlFormTag">&lt;/option&gt;</span>

<span class="htmlFormTag">&lt;/select&gt;</span>

<span class="htmlOtherTag">&lt;/p&gt;</span></pre>
<p><em><a href="http://webdesignfan.com/wp-content/uploads/2011/08/screenshot-of-datepicker-with-date-format-options.jpg"><img class="alignnone size-medium wp-image-8377" title="screenshot of datepicker with date format options" src="http://webdesignfan.com/wp-content/uploads/2011/08/screenshot-of-datepicker-with-date-format-options-300x71.jpg" alt="screenshot of datepicker with date format options 300x71 " width="300" height="71" /></a></em></p>
<h3>Restricting the Date Range</h3>
<p>You can restrict the date ranges on and specify the interval in which one can select the dates. Make use of minDate and maxDate options to set the beginning and end dates of the interval.  For example, if you are using June 6 as current date then minDate = -20D will be 20 days before June 6 and maxDate = +1M 5D will be one month 5days after June 6. The dates will be disabled before minimum date and after maximum date.</p>
<p>You can use following script code and change the minDate &amp; maxDate as per your requirement.</p>
<pre class="javascript">&lt;script&gt;

$(function() {

$("#datepicker").datepicker({minDate: -40, maxDate:"+2M +5D" });

});

&lt;/script&gt;</pre>
<h3>Output</h3>
<p><strong><em> </em></strong></p>
<p><em><a href="http://webdesignfan.com/wp-content/uploads/2011/08/restricting-the-date-range-in-datepicker.jpg"><img class="alignnone size-medium wp-image-8376" title="restricting the date range in datepicker" src="http://webdesignfan.com/wp-content/uploads/2011/08/restricting-the-date-range-in-datepicker-300x112.jpg" alt="restricting the date range in datepicker 300x112 " width="300" height="112" /></a></em></p>
<h3>Displaying the Inline Datepicker</h3>
<p>Well till now we have worked to display the datepicker only when user clicks textbox. There is no scripting for this as you just have to show the datepicker div without any input box. Following is the HTML code to display inline datepicker:</p>
<p>Select the Date: &lt;div&gt;&lt;/div&gt;</p>
<p><em><a href="http://webdesignfan.com/wp-content/uploads/2011/08/inline-jquery-datepicker.jpg"><img class="alignnone size-full wp-image-8375" title="inline jquery datepicker" src="http://webdesignfan.com/wp-content/uploads/2011/08/inline-jquery-datepicker.jpg" alt="inline jquery datepicker " width="255" height="219" /></a></em></p>
<h3>Datepicker with Drop-down Boxes of Years &amp; Months</h3>
<p>To have the drop-down boxes or menus of years and months in a datepicker, you just have to add two Boolean options changeMonth &amp; changeYear and set them to true.</p>
<pre class="html"><span class="htmlScriptTag">&lt;script&gt;</span>

$(function() {

$( &quot;#datepicker&quot; ).datepicker({

changeMonth: true,

changeYear: true

});

});

<span class="htmlScriptTag">&lt;/script&gt;</span></pre>
<p><em><a href="http://webdesignfan.com/wp-content/uploads/2011/08/datepicker-with-menus-of-year-and-months.jpg"><img class="alignnone size-full wp-image-8374" title="datepicker with menus of year and months" src="http://webdesignfan.com/wp-content/uploads/2011/08/datepicker-with-menus-of-year-and-months.jpg" alt="datepicker with menus of year and months " width="258" height="215" /></a></em></p>
<h3>Conclusion</h3>
<p>You can easily add a datepicker using the codes mentioned above. The datepicker is not limited to the above features only. You can also add following features to the datepicker:</p>
<p>●      Populating another text field on selecting a date</p>
<p>●      Displaying buttons on the datepicker</p>
<p>●      Showing dates of other months in the current month</p>
<p>●      Showing weeks of the year</p>
<p>●      Displaying multiple months</p>
<p>●      Adding icon trigger to launch datepicker</p>
<p>●      Date Range with two datepickers one for ‘from’ and another for ‘to’</p>
<h3><strong>Demo &amp; Download</strong></h3>
<p>jQuery Datepicker Demo: <a href="http://webdesignfan.com/demos/demo-jquery-datepicker/demo-datepicker.html">Click here</a></p>
<p>Download the files: <a href="http://webdesignfan.com/demos/demo-jquery-datepicker.zip">demo-jquery-datepicker.zip</a></p>
<p>The zip file will also have the code of above listed features. Please read the readme.txt for details of the contents of zip file.</p>
<p>Unlike <a href="http://www.thetestking.org/exam/MB6-202.html">MB6-202</a> training program, our best <a href="http://www.mytestking.biz/70-441.html">70-441</a> tests and <a href="http://www.pass4sures.biz/MB4-212-testking.html">MB4-212</a> training courses provide you quick success in first try of <a href="http://www.mypass4sure.info/70-506-dumps.html">70-506</a>.
<div class="shr-publisher-8371"></div>
]]></content:encoded>
			<wfw:commentRss>http://webdesignfan.com/integrating-datepicker-with-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building a Compact jQuery News Ticker</title>
		<link>http://webdesignfan.com/building-a-compact-jquery-news-ticker/</link>
		<comments>http://webdesignfan.com/building-a-compact-jquery-news-ticker/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 17:03:34 +0000</pubDate>
		<dc:creator>Nathan Rohler</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://webdesignfan.com/?p=8070</guid>
		<description><![CDATA[<p>Many websites today feature a small news ticker that provides text links to pages with recent news or other features. It's a great way to highlight important links without using much space. In this tutorial, I'll show you how to easily build one of these news tickers using jQuery. We'll start with a HTML list of links, then use jQuery to make them automatically cycle, fading in and out. When the user hovers over a link, the ticker will pause so they can click the link to learn more.</p>]]></description>
			<content:encoded><![CDATA[<p>Many websites today feature a small news ticker that provides text links to pages with recent news or other features. It&#8217;s a great way to highlight important links without using much space. In this tutorial, I&#8217;ll show you how to easily build one of these news tickers using jQuery. We&#8217;ll start with a HTML list of links, then use jQuery to make them automatically cycle, fading in and out. When the user hovers over a link, the ticker will pause so they can click the link to learn more.</p>
<p>Before getting started, be sure to view the demo to see how the ticker works. Here&#8217;s what the finished project will look like:</p>
<div class="tutorial_image"><img src="/tutimg/newsticker/images/finished.png" width="541" height="409" alt="Finished ticker" title="Building a Compact jQuery News Ticker" /></div>
<p><a href="/tutimg/newsticker/files/finished.html">HTML Demo</a></p>
<p><span id="more-8070"></span></p>
<hr />
<h2>Tutorial Details</h2>
<ul>
<li><b>Technologies</b>: HTML, CSS, JavaScript, jQuery</li>
<li><b>Difficulty:</b> Intermediate</li>
<li><b>Estimated Completion Time:</b> 20-30 minutes</li>
</ul>
<hr />
<h2> <span>Intro:</span> Preparations</h2>
<p>You should create an empty HTML file and save it somewhere convenient now; we&#8217;ll be working with it throughout this tutorial. We&#8217;ll be working exclusively with client-side code, so there&#8217;s no need for a server &#8211; you can preview directly on your computer. In the demo files we&#8217;ll use inline CSS and JavaScript, but you can externalize these if desired.</p>
<p><strong> Tip:</strong> For this type of tutorial, it can be helpful to use <a href="http://jsbin.com/" target="_blank">jsBin</a> or <a href="http://jsfiddle.net/" target="_blank">jsFiddle</a> to follow along. These free online tools let you experiment with HTML, JavaScript and CSS without having to create any files on your computer. Best of all, you can save, version and share your experiments.  It&#8217;s a great way to perfect a technique without cluttering up your computer with tons of files.</p>
<p>If you&#8217;re creating your own HTML file, here&#8217;s the code you should have to start:</p>
<pre name="code" class="html">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head>
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

  &lt;title>jQuery News Ticker&lt;/title>
  &lt;style type="text/css">
  /* CSS will go here */

  &lt;/style>
&lt;/head>

&lt;body>

  &lt;!-- Markup will go here --&gt;

  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js">&lt;/script>
  &lt;script type="text/javascript">
  // JavaScript will go here

  &lt;/script>
&lt;/body>
&lt;/html>
</pre>
<p>Note the designated places for markup, CSS and JavaScript. Additionally, note that we have included jQuery 1.6 from Google&#8217;s CDN.</p>
<hr />
<h2> <span>Step 1:</span> The HTML Markup</h2>
<p>We&#8217;ll use a dedicated <code>&lt;div&gt;</code> to hold the ticker. The links will be contained within an unordered list (<code>&lt;ul&gt;</code>). By using an HTML list to define the links, we ensure that the ticker will gracefully degrade for users with JavaScript disabled, and that search engines will still be able to see and follow all of the links. Add the following HTML markup to your page:</p>
<pre name="code" class="html">
&lt;div id=&quot;ticker&quot; class=&quot;newsTicker&quot;&gt;
    &lt;a href=&quot;#&quot;&gt;Newsroom&lt;/a&gt;
    &lt;span class=&quot;divider&quot;&gt;|&lt;/span&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#story1&quot;&gt;Story headline 1&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#story2&quot;&gt;Another Story headline 2&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#story3&quot;&gt;Some third story headline&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#story4&quot;&gt;A final, fourth headline&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>Update the list to contain an <code>&lt;li&gt;</code> for each of the links you want in the ticker. I&#8217;ve chosen to put a &#8216;Newsroom&#8217; link at the start, but that&#8217;s up to you.</p>
<hr />
<h2> <span>Step 2:</span> Styling</h2>
<p>Now it&#8217;s time to make the scroller look nice. In the <code>&lt;style&gt;</code> tag in the <code>&lt;head&gt;</code>, add the following CSS:</p>
<pre>
#ticker
{
    border: 1px solid #666;
    background: #DDD;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    color: #333;
    font: 13px/16px Arial,Verdana,sans-serif;
    padding: 3px 7px;
    width: 400px;
}
#ticker .divider {
    padding: 0 4px;
}
#ticker a, #ticker a:visited
{
    color: #333;
    text-decoration: none;
}
#ticker a:hover
{
    color: #930;
}
</pre>
<p> This adds some background and border to the overall ticker, and styles the links. These styles are just to get you started &#8211; if you want, you can add some creativity at this point! As we style, keep in mind that the &lt;ul&gt; won&#8217;t be present in the rendered HTML &#8211; it will be replaced with a single link that changes. That&#8217;s why there are only link styles and no list-related styling.</p>
<hr />
<h2> <span>Step 3:</span> Making It Work</h2>
<p>Now we&#8217;re ready to add the jQuery-enhanced JavaScript to make the ticker actually work. I&#8217;ll show you the overall chunk first, then break down what each portion is doing. </p>
<p>Add the following chunk of JavaScript to the <code>&lt;script&gt;</code> tag at the bottom of the page:</p>
<pre name="code" class="js">
$(function()
{
    $('#ticker').each(function()
    {
        var ticker = $(this);
        var fader = $('&lt;span class=&quot;fader&quot;&gt;&amp;nbsp;&lt;/span&gt;').css({display:'inline-block'});
        var links = ticker.find('ul&gt;li&gt;a');
        ticker.find('ul').replaceWith(fader);

        var counter = 0;
        var curLink;
        var fadeSpeed = 600;
        var showLink = function()
            {
                var newLinkIndex = (counter++) % links.length;
                var newLink = $(links[newLinkIndex]);
                var fadeInFunction = function()
                    {
                        curLink = newLink;
                        fader.append(curLink).fadeIn(fadeSpeed);
                    };
                if (curLink)
                {
                    fader.fadeOut(fadeSpeed, function(){
                        curLink.remove();
                        setTimeout(fadeInFunction, 0);
                    });
                }
                else
                {
                    fadeInFunction();
                }
            };

        var speed = 5500;
        var autoInterval;

        var startTimer = function()
        {
            autoInterval = setInterval(showLink, speed);
        };
        ticker.hover(function(){
            clearInterval(autoInterval);
        }, startTimer);

        fader.fadeOut(0, function(){
            fader.text('');
            showLink();
        });
        startTimer();

    });
});
</pre>
<p>If you preview  now, you should see a working ticker that cycles through all of your links.  If you hover over the ticker, it will pause; if you move your mouse away again, it will restart. Now, let&#8217;s break down what all of that code is doing.</p>
<h3>Breaking Down the JavaScript &#8211; Overview</h3>
<p>In plain English, here&#8217;s what the JavaScript is doing:</p>
<ul>
<li>Everything is wrapped in a document-ready trigger, so it will be called once the document is ready for manipulation</li>
<li>We locate the news ticker</li>
<li>We create an array that references the links, then replace the unordered list element in the document with a holder <code>span</code>.  That holder will be used for displaying the current link.</li>
<li>We define a function that transitions from one link to the next</li>
<li>We create a timer, and set it to automatically pause when the user hovers over the ticker</li>
<li>We show the first link and start running the timer</li>
</ul>
<h3>Breaking Down the JavaScript &#8211; Details</h3>
<p>Now, lets take an in-depth look at what each of these pieces of code is doing. </p>
<p>Note that we use the <code>#ticker</code> selector to locate the ticker. If you had multiple tickers in your page, you could change this to <code>div.newsTicker</code> instead, since we applied a class of <code>newsTicker</code> to our ticker.</p>
<p><strong>Chunk 1 &#8211; Finding the content, Preparing the document</strong></p>
<pre name="code" class="js">
var ticker = $(this);
var fader = $('&lt;span class=&quot;fader&quot;&gt;&amp;nbsp;&lt;/span&gt;').css({display:'inline-block'});
var links = ticker.find('ul&gt;li&gt;a');
ticker.find('ul').replaceWith(fader);
</pre>
<p>In this first chunk, we create a jQuery reference</p>
<p>  to the current ticker. Then, we create a new <code>&lt;span&gt;</code> that will be used to hold the current link.  The <code>fader</code> class is applied, to enable styling if desired. Note that we set the <code>display</code> property of the span to <code>inline-block</code>.  This is important to enable fading of the text in Internet Explorer.  Without some annoyingly-complex trickery (treating the text as a block-level element to be precise), IE fails to fade the text. Next, we create a jQuery list that references all of the link elements that were defined in the markup, so we can use them later on. Having created this list, we destroy the unordered list, replacing it with the <code>fader</code> span.
</p>
<p><strong>Chunk 2 &#8211; Creating the &quot;Show me a new link&quot; function</strong></p>
<pre name="code" class="js">
var counter = 0;
var curLink;
var fadeSpeed = 600;
var showLink = function()
    {
        var newLinkIndex = (counter++) % links.length;
        var newLink = $(links[newLinkIndex]);
        var fadeInFunction = function()
            {
                curLink = newLink;
                fader.append(curLink).fadeIn(fadeSpeed);
            };
        if (curLink)
        {
            fader.fadeOut(fadeSpeed, function(){
                curLink.remove();
                setTimeout(fadeInFunction, 0);
            });
        }
        else
        {
            fadeInFunction();
        }
    };
</pre>
<p>In this next major chunk, we define the method that will fade the link in and out.  A counter keeps track of which link we&#8217;re on.  The <code>fadeSpeed</code> variable specifies how fast the fade effect should be.  By default, we use 600 milliseconds (0.6 seconds). Next, we define the function that will swap out the links. In this function we increment the counter and select the next link in the earlier-created list, automatically cycling back to the first by using the <a href="http://en.wikipedia.org/wiki/Modulo_operator" target="_blank">modulus operator</a> (%).  Then we define a temporary function that updates the reference to the current link, adds it to the <code>fader</code> span, then fades it in. Note that we fade the fader, not the link itself;  this is part of the trickery to make the fading work properly in IE.  Finally, we check to see if a link already is being displayed.  If so, we first fade out the fader and remove that link upon effect completion.  Then, after a microscopic delay to avoid item reference problems, we call the method to display the new link.  On the other hand, if no link exists, we just display the new link directly.</p>
<p><strong>Chunk 3 &#8211; Configuring Automatic progression, Starting it up</strong></p>
<pre name="code" class="js">
var speed = 5500;
var autoInterval;

var startTimer = function()
{
    autoInterval = setInterval(showLink, speed);
};
ticker.hover(function(){
    clearInterval(autoInterval);
}, startTimer);

fader.fadeOut(0, function(){
    fader.text('');
    showLink();
});
startTimer();
</pre>
<p>In the final chunk, we start things running. The speed variable defines (again, in milliseconds) how long each link should be visible when the ticker is automatically progressing. By default, we use 5500 (5.5 seconds). We define a <code>startTimer</code> method that creates an interval to call the earlier-defined <code>showLink</code> method every few seconds. Next, we add the listener that will automatically pause and restart the ticker when the user hovers over and leaves it. Then, to start the initial display, we instantly fade out the fader, empty its existing contents (a space character that&#8217;s required to force it to fade), and use <code>showLink</code> to fade in the first link. Finally, we start the timer.</p>
<hr />
<h2> <span>Summary</span></h2>
<p>You&#8217;ve now created a simple, compact news ticker to display newsworthy links on your site. The ticker functions properly in all browsers (including IE!) and automatically pauses when hovered-over, to ensure a good user experience. To enhance the ticker, you could use a server-side script (like PHP) to dynamically output the links. There are many possibilities! Moreover, you&#8217;ve learned about how jQuery&#8217;s document manipulation and effect tools can be leveraged to create nifty, useful widgets for your page. Have fun with your new knowledge!</p>
<div class="shr-publisher-8070"></div>
]]></content:encoded>
			<wfw:commentRss>http://webdesignfan.com/building-a-compact-jquery-news-ticker/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>htmlspecialchars in JavaScript</title>
		<link>http://webdesignfan.com/htmlspecialchars-in-javascript/</link>
		<comments>http://webdesignfan.com/htmlspecialchars-in-javascript/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 14:30:42 +0000</pubDate>
		<dc:creator>Charles Stover</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Premium]]></category>
		<category><![CDATA[htmlspecialchars]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://webdesignfan.com/?p=6650</guid>
		<description><![CDATA[htmlspecialchars is an extremely useful PHP function, but proves useful in more languages that just PHP. It is necessary to use these HTML entities whenever you want HTML to display as plain text instead of being parsed.]]></description>
			<content:encoded><![CDATA[<h3><a name="tutorial"></a>In This Tutorial</h3>
<ol>
<li><a href="#intro">Introduction</a></li>
<li><a href="#code">The Code</a></li>
<li><a href="#why">Why <code>reverse()</code>?</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
<h3><a name="intro"></a>Introduction</h3>
<p><var>htmlspecialchars</var> is an extremely useful <a href="http://us2.php.net/manual/en/function.htmlspecialchars.php" title="PHP: htmlspecialchars - Manual">PHP function</a>. It&#8217;s use is defined by the PHP manual as such:</p>
<blockquote>
<p>Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with some of these conversions made; the translations made are those most useful for everyday web programming&#8230;</p>
<p>This function is useful in preventing user-supplied text from containing HTML markup, such as in a message board or guest book application.</p>
<p>The translations performed are:</p>
<ul>
<li>&#8216;&amp;&#8217; (ampersand) becomes &#8216;&amp;amp;&#8217;</li>
<li>&#8216;&quot;&#8217; (double quote) becomes &#8216;&amp;quot;&#8217;&#8230;</li>
<li>&#8216;&lt;&#8217; (less than) becomes &#8216;&amp;lt;&#8217;</li>
<li>&#8216;&gt;&#8217; (greater than) becomes &#8216;&amp;gt;&#8217;</li>
</ul>
</blockquote>
<p>However, this function proves useful in more languages that just PHP. It is necessary to use these HTML entities whenever you want HTML to display as plain text instead of being parsed, in whatever language you may be using to output it. In my <a href="http://webdesignfan.com/how-to-make-a-graphical-news-slider-in-jquery/">news slider</a> tutorial, I used this function to store HTML as an image&#8217;s <var>alt</var> attribute.</p>
<pre class="">
&lt;img alt=&quot;&lt;a href=&quot;http://www.charlesstover.com/&quot;&gt;Charles Stover&lt;/a&gt;&quot; src=&quot;...&quot; /&gt;
</pre>
<p>The above is <strong>not</strong> valid markup. The quotes inside the alt attribute will cause it to end the attribute after <code>href=</code>, ignoring the rest of the string. To successful store symbols such as &quot; inside of double-quoted strings, we must [or at least should] convert them to HTML entities.</p>
<pre class="">
&lt;img alt=&quot;&amp;lt;a href=&amp;quot;http://www.charlesstover.com/&amp;quot;&amp;gt;Charles Stover&amp;lt;/a&amp;gt;&quot; src=&quot;...&quot; /&gt;
</pre>
<p>The above <strong>is</strong> valid markup.</p>
<p>A more realistic JavaScript example would be outputting user input on the screen. Say you have some custom-built command prompt that allows user input and displays a history of commands entered. You can&#8217;t merely display what they type in, because if they were to type <code>&lt;strong&gt;command&lt;/strong&gt;</code>, it would output as <strong>command</strong>. It is precisely situations like these that <var>htmlspecialchars</var> was invented.</p>
<p>Unfortunately, this function does not exist by default in all languages. For this reason, I have ported a similar (but not exact, as I have never needed an exact) copy in JavaScript.</p>
<p>What it does is take a string, such as <code>&lt;strong&gt;command&lt;/strong&gt;</code>, and converts it to its HTML-entities form, such as <code>&amp;lt;strong&amp;gt;command&amp;lt;/strong&amp;gt;</code>, so that it may be output safely.</p>
<p>I added a useful second parameter <var>reverse</var> that was necessary in the news slider. When <var>reverse</var> is set (boolean <var>true</var> works fine), the function will convert an HTML-entitied string, such as <code>&amp;lt;strong&amp;gt;command&amp;lt;/strong&amp;gt;</code>, and convert it back to HTML, such as <code>&lt;strong&gt;command&lt;/strong&gt;</code>. This was necessary to retrieve and output the &quot;translated&quot; <var>alt</var> value of the images as HTML.</p>
<div><a href="#tutorial">Back to Top</a></div>
<h3><a name="code"></a>The Code</h3>
<p>This is a very short code, and as such I will condense the code down to a single section with the comments on the functionality inside the code itself. The only exception being the explanation for the need to use <var>reverse()</var> is explained at the end of this article in <a href="#why">Why <code>reverse()</code>?</a></p>
<pre class="javascript">
// Create the function.
// First parameter: the string
// Second parameter: whether or not to &quot;undo&quot; the translation
var htmlSpecialChars = function(string, reverse)
	{

		// specialChars is a list of characters and that to which to translate them.
		// specialChars[&quot;&lt;&quot;] = &quot;&amp;lt;&quot;;
		// x is merely a variable used in for loops.
		var specialChars = {
				&quot;&amp;&quot;: &quot;&amp;amp;&quot;,
				&quot;&lt;&quot;: &quot;&amp;lt;&quot;,
				&quot;&gt;&quot;: &quot;&amp;gt;&quot;,
				'&quot;': &quot;&amp;quot;&quot;
			}, x;

		// If we are reversing the translation...
		if (typeof(reverse) != &quot;undefined&quot;)
		{

			// We need to create a temporary array.
			reverse = [];

			// Put each special character in the array.
			for (x in specialChars)
				reverse.push(x);

			// Reverse the array.
			// [&quot;&lt;&quot;, &quot;&gt;&quot;] becomes [&quot;&gt;&quot;, &quot;&lt;&quot;]
			reverse.reverse();

			// For each of the special characters,
			for (x = 0; x &lt; reverse.length; x++)

				// Replace all instances (g) of the entity with the original.
				// e.g. if x = 1, then
				// reverse[x] = reverse[1] = &quot;&gt;&quot;;
				// specialChars[reverse[x]] = specialChars[&quot;&gt;&quot;] = &quot;&amp;gt;&quot;;
				string = string.replace(
					new RegExp(specialChars[reverse[x]], &quot;g&quot;),
					reverse[x]
				);

			// Return the reverse-translated string.
			// Returning a value ends the function,
			// therefore no code after this line will execute,
			// therefore no need to use the else conditional.
			return string;
		}

		// If we are not reversing a translation,
		// For each of the special characters,
		for (x in specialChars)

			// Replace all instances of the special character with its entity.
			// Remember, unlike in the reverse algorithm where x is an integer,
			// x here is the key value (e.g. &amp;, &lt;, &gt;, and &quot;)
			string = string.replace(new RegExp(x, &quot;g&quot;), specialChars[x]);

		// Return the translated string.
		return string;
	};
</pre>
<div><a href="#tutorial">Back to Top</a></div>
<h3><a name="why"></a>Why <code>reverse()</code>?</h3>
<p>For those wondering why the temporary array was reversed (or why the temporary array even needed to exist), nothing explains better than an example. The ampersand in a regular (i.e. not reverse) translation must be translated before the other three characters, because the ampersand is a part of the entity!</p>
<pre class="javascript">
// Translating ampersand first:
var string = &quot;&lt;&quot;; // &lt;
string = string.replace(/&amp;/g, &quot;&amp;amp;&quot;); // &lt;
string = string.replace(/&lt;/g, &quot;&amp;lt;&quot;); // &amp;lt;
alert(string); // &amp;lt;

// Translating ampersand last:
var string = &quot;&lt;&quot;; // &lt;
string = string.replace(/&lt;/g, &quot;&amp;lt;&quot;); // &amp;lt;
string = string.replace(/&amp;/g, &quot;&amp;amp;&quot;); // &amp;amp;lt;
alert(string); // &amp;amp;lt;
</pre>
<p>Since &amp;lt; contains an ampersand, the ampersand in it will be translated. Thus, we translate the ampersand before we translate anything else.</p>
<p>That settled, why reverse the array? For the exact same reason. If it&#8217;s the first to translate going forward, it must be the last to translate going in reverse. This is most noteable when using HTML entities.</p>
<p>If the user types <code>&amp;amp;lt;</code>, you&#8217;ll want <code>&amp;amp;lt;</code> to display, not <code>&amp;lt;</code>. But let&#8217;s say we&#8217;re in a scenario where want to reverse this code to actual HTML. Perhaps it&#8217;s the <var>alt</var> attribute of an image in the aforementioned news slider. Perhaps it&#8217;s the HTML code in a <var>textarea</var> that allows users to embed the video on their websites. Wherever it came from, we have HTML that contains entities, and we want to remove them. We want to convert <code>&amp;amp;lt;</code> to <code>&amp;lt;</code>!</p>
<pre class="javascript">
// Reverse translating ampersand first:
var string = &quot;&amp;amp;lt;&quot;; // &amp;amp;lt;
string = string.replace(/&amp;amp;/g, &quot;&amp;&quot;); // &amp;lt;
string = string.replace(/&amp;lt;/g, &quot;&lt;&quot;); // &lt;
alert(string); // &lt;

// Reverse translating ampersand last:
var string = &quot;&amp;amp;lt;&quot;; // &amp;amp;lt;
string = string.replace(/&amp;lt;/g, &quot;&lt;&quot;); // &amp;amp;lt;
string = string.replace(/&amp;amp;/g, &quot;&amp;&quot;); // &amp;lt;
alert(string); // &amp;lt;
</pre>
<p>When ampersand translates first, the process will translate one time too many. Just like with forward-translation, where <code>&lt;</code> (translating &lt;) becomes <code>&amp;lt</code> (translating &amp;) becomes <code>&amp;amp;lt;</code> when translated out of order, reverse translation undergoes the same problem: <code>&amp;amp;lt;</code> (reverse translating &amp;) becomes <code>&amp;lt;</code> (reverse translating &lt;) becomes <code>&lt;</code>.</p>
<div><a href="#tutorial">Back to Top</a></div>
<h3><a name="conclusion"></a>Conclusion</h3>
<p>Go forth and be prosperous. This code, being so short, is free for you to use and distribute. Just don&#8217;t claim ownership of it and all that other legal jargon. I hope you all find great use for it.</p>
<div><a href="#tutorial">Back to Top</a></div>
<p>Cut down your exam stress by using our latest <a href="http://www.thetestking.info/Microsoft-guide.html">testking microsoft</a> high quality exam and <a href="http://www.thepass4sure.info/70-557-test.html">70-557</a>. We provide updated questions with 100% pass guarantee along with <a href="http://www.pass4sures.biz/MB7-224-testking.html">MB7-224</a> and <a href="http://www.mypass4sure.info/70-647-dumps.html">70-647</a>.
<div class="shr-publisher-6650"></div>
]]></content:encoded>
			<wfw:commentRss>http://webdesignfan.com/htmlspecialchars-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
