<?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>vijayjoshi.org &#187; FAQ</title>
	<atom:link href="http://www.vijayjoshi.org/tag/faq/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vijayjoshi.org</link>
	<description>php &#124; javascript &#124; ajax &#124; and all things web</description>
	<lastBuildDate>Sun, 20 Nov 2011 15:24:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Comment box not visible on a page/post in WordPress 3.2.1</title>
		<link>http://www.vijayjoshi.org/2011/10/21/comment-box-not-visible-on-a-pagepost-in-wordpress-3-2-1/</link>
		<comments>http://www.vijayjoshi.org/2011/10/21/comment-box-not-visible-on-a-pagepost-in-wordpress-3-2-1/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 11:09:22 +0000</pubDate>
		<dc:creator>Vijay Joshi</dc:creator>
				<category><![CDATA[FAQ]]></category>

		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=1312</guid>
		<description><![CDATA[
			
				
			
		
First of all I will congratulate you on upgrading to wordpress 3.2.1. Having latest version means your site is updated and safe.
Now coming to the point, some of you might have faced this problem. You create a new page or post and do not want to allow comments on that. So you scroll down but cannot find the discussion box. ...]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2011%2F10%2F21%2Fcomment-box-not-visible-on-a-pagepost-in-wordpress-3-2-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2011%2F10%2F21%2Fcomment-box-not-visible-on-a-pagepost-in-wordpress-3-2-1%2F&amp;source=v08i&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>First of all I will congratulate you on upgrading to wordpress 3.2.1. Having latest version means your site is updated and safe.</p>
<p>Now coming to the point, some of you might have faced this problem. You create a new page or post and do not want to allow comments on that. So you scroll down but cannot find the discussion box. The box which has 2 checkboxes &#8220;Allow comments&#8221; and &#8220;Allow trackbacks and pingbacks&#8221;.</p>
<p>To fix this, look at the top right of your screen for the <strong>Screen Options</strong> button. Click that and you will see a lot of checkboxes there. Click the <strong>Discussion</strong>  checkbox and close the screen options. Now scroll to bottom of the page and you will find the box sitting there.</p>
<p><a href="http://www.vijayjoshi.org/wp-content/uploads/wp-comments.png"><img class="aligncenter size-full wp-image-1313" title="wp-comments" src="http://www.vijayjoshi.org/wp-content/uploads/wp-comments.png" alt="Enable comments" width="656" height="268" /></a></p>
<p>WP3.2.1 has several other options like Custom fields, slug, Author which you can also enable from here.</p>
<div class="shr-publisher-1312"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.vijayjoshi.org%2F2011%2F10%2F21%2Fcomment-box-not-visible-on-a-pagepost-in-wordpress-3-2-1%2F' data-shr_title='Comment+box+not+visible+on+a+page%2Fpost+in+Wordpress+3.2.1'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.vijayjoshi.org/2011/10/21/comment-box-not-visible-on-a-pagepost-in-wordpress-3-2-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Tip: Finding tag name of an element</title>
		<link>http://www.vijayjoshi.org/2010/11/20/jquery-tip-finding-tag-name-of-an-element/</link>
		<comments>http://www.vijayjoshi.org/2010/11/20/jquery-tip-finding-tag-name-of-an-element/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 05:30:02 +0000</pubDate>
		<dc:creator>Vijay Joshi</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[FAQ]]></category>

		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=644</guid>
		<description><![CDATA[
			
				
			
		
While coding jQuery or javascript, sometimes we need the tag name of an element. This post will show how you can retrieve the tag name of an element easily using jQuery
We know that each DOM element has a tagName property. We also know that most jQuery methods return jQuery object. Therefore to get the tagName, we need to extract the ...]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2010%2F11%2F20%2Fjquery-tip-finding-tag-name-of-an-element%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2010%2F11%2F20%2Fjquery-tip-finding-tag-name-of-an-element%2F&amp;source=v08i&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>While coding jQuery or javascript, sometimes we need the tag name of an element. This post will show how you can retrieve the tag name of an element easily using jQuery</p>
<p>We know that each DOM element has a <em>tagName </em>property. We also know that most jQuery methods return jQuery object. Therefore to get the tagName, we need to extract the DOM element from it. This can be achieved in 2 ways.</p>
<p><strong>Method 1: Using get() method of jQuery</strong></p>
<p>jQuery&#8217;s <em>get()</em> method returns the collection of DOM elements for a jQuery collection.</p>
<p>Consider the following markup</p>
<pre class="brush:html">
<div id="firstDiv">This is a div</div>
</pre>
<p><span id="more-644"></span><br />
In this case <em>$(&#8216;#firstDiv&#8217;)</em> will be the jQuery object for above div. To get tag name for correspoding DOM element use the following</p>
<pre lang="javascript">var element = $('#firstDiv').get(0);
var tagName = element.tagName;</pre>
<p>Note that get() returns an array, hence 0 based indexes to retrieve elements. Have a look at another example.</p>
<pre class="brush:html">
<div id="secondDiv">
<input type="text" value="text box" />

paragraph element

    <span>span element</span>
</div>
</pre>
<pre class="brush:js">var a = $('#secondDiv').children().get(0); // INPUT
var b = $('#secondDiv').children().get(1); // P
var c = $('#secondDiv').children().get(2); // SPAN</pre>
<p><strong>Method 2: Using this</strong></p>
<p>You can also use this to refer to DOM elements as shown in next example. Code below use the same markup for secondDiv.</p>
<pre class="brush:js">$('#secondDiv').children().each(function()
{
	var tagName = (this.tagName).toLowerCase();
});</pre>
<p>The returned tag names will all be in uppercase. You can use javascript function toLowerCase to make them XHTML compliant i.e. lower case.</p>
<div class="shr-publisher-644"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.vijayjoshi.org%2F2010%2F11%2F20%2Fjquery-tip-finding-tag-name-of-an-element%2F' data-shr_title='jQuery+Tip%3A+Finding+tag+name+of+an+element'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.vijayjoshi.org/2010/11/20/jquery-tip-finding-tag-name-of-an-element/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick PHP Tip: How to parse CDATA sections using SimpleXML</title>
		<link>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/</link>
		<comments>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 08:41:39 +0000</pubDate>
		<dc:creator>Vijay Joshi</dc:creator>
				<category><![CDATA[FAQ]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=393</guid>
		<description><![CDATA[
			
				
			
		
Applies to:  simplexml_load_string and simplexml_load_file
Problem : SimpleXML does not parse text inside CDATA tags in an XML.
Consider the XML below:


$str = '';
$str.='some text goes here';
$str.='';

To parse it we use following syntax:
$xml = simplexml_load_string($str);
On printing it outputs:


SimpleXMLElement Object
(
    [childNode] => some text goes here
)

Thats OK. Now the same xml but this time the text is enclosed in CDATA ...]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F09%2F22%2Fquick-php-tip-how-to-parse-cdata-sections-using-simplexml%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F09%2F22%2Fquick-php-tip-how-to-parse-cdata-sections-using-simplexml%2F&amp;source=v08i&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h4>Applies to:  simplexml_load_string and simplexml_load_file</h4>
<h4>Problem : SimpleXML does not parse text inside CDATA tags in an XML.</h4>
<p>Consider the XML below:</p>
<pre class="brush:php">

$str = '<rootNode>';
$str.='<childNode>some text goes here</childNode>';
$str.='</rootNode>';
</pre>
<p>To parse it we use following syntax:</p>
<pre class="brush:php">$xml = simplexml_load_string($str);</pre>
<p>On printing it outputs:</p>
<pre class="brush:php">

SimpleXMLElement Object
(
    [childNode] => some text goes here
)
</pre>
<p>Thats OK. Now the same xml but this time the text is enclosed in CDATA tags.</p>
<pre class="brush:php">

$str = '<rootNode>';
$str.='<childNode><![CDATA[some text goes here]]&gt;</childNode>';
$str.='</rootNode>'
</pre>
<p>On printing this gives following output:</p>
<pre class="brush:php">

SimpleXMLElement Object
(
    [childNode] => SimpleXMLElement Object
        (
        )

)
</pre>
<p>Yes its empty. This is because SimpleXML does not parse CDATA tags. All data enclosed within CDATA is ignored by SimpleXML parser.</p>
<h4>Solution: Set the 3rd parameter to LIBXML_NOCDATA while parsing.</h4>
<p>simplexml_load_string(simplexml_load_file too) actually takes 3 parameters.</p>
<ul>
<li>The string to parse</li>
<li>Optional parameter &#8211; to return an object of class specified in this parameter. (By default it returns a SimpleXMLElement Object)</li>
<li>Also optional &#8211; libxml parameters can be specified as options. This option provides the solution to our CDATA problem</li>
</ul>
<p>Provide the 3rd parameter LIBXML_NOCDATA and SimpleXML will consider CDATA nodes as text nodes and will parse them.</p>
<pre class="brush:php">

$xml = simplexml_load_string($str,'SimpleXMLElement', LIBXML_NOCDATA);
</pre>
<p>This will output as desired:</p>
<pre class="brush:php">

SimpleXMLElement Object
(
    [childNode] => some text goes here
)
</pre>
<p>Please note that using the third parameter requires PHP >=5.1 compiled with libxml.</p>
<p>I will be publishing a new post shortly on how to use SimpleXML to parse xml and extract data.</p>
<div class="shr-publisher-393"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F09%2F22%2Fquick-php-tip-how-to-parse-cdata-sections-using-simplexml%2F' data-shr_title='Quick+PHP+Tip%3A+How+to+parse+CDATA+sections+using+SimpleXML'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FAQ : How to toggle visibility of an html element by javascript</title>
		<link>http://www.vijayjoshi.org/2009/01/27/faq-how-to-toggle-visibility-of-an-html-element-by-javascript/</link>
		<comments>http://www.vijayjoshi.org/2009/01/27/faq-how-to-toggle-visibility-of-an-html-element-by-javascript/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 09:37:48 +0000</pubDate>
		<dc:creator>Vijay Joshi</dc:creator>
				<category><![CDATA[FAQ]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=264</guid>
		<description><![CDATA[
			
				
			
		
In my previous post, I discussed how we can change the style and/or css class of any html element by JavaScript. We can take advantage of this feature to add functionality where visibility of elements can be toggled. That means clicking a button will change the state of that element from visible to invisible and vice-versa.
The css property that we ...]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F01%2F27%2Ffaq-how-to-toggle-visibility-of-an-html-element-by-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F01%2F27%2Ffaq-how-to-toggle-visibility-of-an-html-element-by-javascript%2F&amp;source=v08i&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In my <a title="Change css of elements from javascript" href="http://www.vijayjoshi.org/2009/01/24/setting-stylecss-class-of-html-elements-from-javascript/" target="_self">previous post</a>, I discussed how we can change the style and/or css class of any html element by JavaScript. We can take advantage of this feature to add functionality where visibility of elements can be toggled. That means clicking a button will change the state of that element from visible to invisible and vice-versa.</p>
<p>The css property that we will manipulate to achieve this behavior is &#8220;display&#8221;. Below is the html we will use for the example.</p>
<pre class="brush:js">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Toggle elements&lt;/title&gt;
&lt;script type="text/javascript" language="javascript"&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div style="border:2px solid;"&gt;
&lt;p&gt;&lt;input type="button" onClick="toggleMe('toggleHolmes');" value="Click to toggle"/&gt;&lt;/p&gt;
&lt;p id="toggleHolmes" style="display:block;"&gt;
I consider that a mans brain originally is like a little empty attic, and you have to stock it with such furniture as you choose. A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it.&lt;br/&gt;
-Sherlock Holmes (A Study in Scarlet - Part 1,chap. 2)
&lt;/p&gt;
&lt;/div&gt;
&lt;br/&gt;
&lt;div style="border:2px solid;"&gt;
&lt;p&gt;&lt;input type="button" onClick="toggleMe('toggleNietzsche');" value="Click to toggle"/&gt;&lt;/p&gt;
&lt;p id="toggleNietzsche" style="display:block;"&gt;
God is dead. God remains dead. And we have killed him. How shall we comfort ourselves, the murderers of all murderers? What was holiest and mightiest of all that the world has yet owned has bled to death under our knives: who will wipe this blood off us? What water is there for us to clean ourselves? What festivals of atonement, what sacred games shall we have to invent? Is not the greatness of this deed too great for us? Must we ourselves not become gods simply to appear worthy of it?&lt;br/&gt;
-"The Madman" (Thus Spoke Zarathustra by Friedrich Nietzsche)
&lt;/p&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>There are 2 paragraphs with ids &#8220;toggleHolmes&#8221; and &#8220;toggleNietzsche&#8221; which contain some text. Above each of them is a button. Onclick of each of those buttons we have called a function toggleMe which accepts the id of the element which is to be toggled as its parameter.<br />
Now include the following JavaScript code between the script tags in above html.<br />
<span id="more-264"></span></p>
<pre class="brush:js">
function toggleMe(id)
{
	var element = document.getElementById(id);
	if(element.style.display == "none")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.display = "none";
	}
}
</pre>
<p>Let us analyze it. Function toggleMe gets the id of element.Here we follow the following steps:<br />
Check whether the display property of element is already set to none.<br />
If it is none we need to change it to block.<br />
Otherwise it is visible and therefore we set it to none.</p>
<p>Now go ahead and click the button. Clicking button will make the respective paragraph visible and hidden alternatively.<br />
In case you are interested these all lines of toggleMe function can be replaced by a single line. The magic of <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/Conditional_Operator" target="_blank">Conditional Operator</a> <img src='http://www.vijayjoshi.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush:js">
element.style.display = (element.style.display == "none") ? "block" : "none";
</pre>
<p>Above example can be seen in action at <a href="http://vijayjoshi.org/examples/toggle.html" target="_blank">http://vijayjoshi.org/examples/toggle.html</a></p>
<div class="shr-publisher-264"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F01%2F27%2Ffaq-how-to-toggle-visibility-of-an-html-element-by-javascript%2F' data-shr_title='FAQ+%3A+How+to+toggle+visibility+of+an+html+element+by+javascript'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.vijayjoshi.org/2009/01/27/faq-how-to-toggle-visibility-of-an-html-element-by-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FAQ : Problem with javascript function parseInt</title>
		<link>http://www.vijayjoshi.org/2009/01/07/faq-problem-with-javascript-function-parseint/</link>
		<comments>http://www.vijayjoshi.org/2009/01/07/faq-problem-with-javascript-function-parseint/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 06:36:06 +0000</pubDate>
		<dc:creator>Vijay Joshi</dc:creator>
				<category><![CDATA[FAQ]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=245</guid>
		<description><![CDATA[
			
				
			
		
JavaScript function parseInt() is used to parse a string and extract the integer from that string.
Therefore if you do parseInt(&#8220;200xyz&#8221;), it will return 200.
The problem arises when you do the following:
var value = "010";
alert(parseInt(value)); // incorrect: will alert 8
You had expected 10 but what you got is 8.
Weird behavior, you must be thinking.
Actually not.It is a lesser known fact that ...]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F01%2F07%2Ffaq-problem-with-javascript-function-parseint%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F01%2F07%2Ffaq-problem-with-javascript-function-parseint%2F&amp;source=v08i&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>JavaScript function parseInt() is used to parse a string and extract the integer from that string.<br />
Therefore if you do parseInt(&#8220;200xyz&#8221;), it will return 200.<br />
The problem arises when you do the following:</p>
<pre class="brush:js">var value = "010";
alert(parseInt(value)); // incorrect: will alert 8</pre>
<p>You had expected 10 but what you got is 8.</p>
<p>Weird behavior, you must be thinking.</p>
<p>Actually not.It is a lesser known fact that parseInt actually takes two arguments, second of which is optional.</p>
<p>First argument is the string to parse and second is radix, which can be any one of base 10, base 2, base 8 or others.</p>
<p>If second argument is not given. parseInt does not always assume it to be 10. It parses the string on following assumptions:</p>
<blockquote>
<ul>
<li>If the string starts with &#8220;0&#8243;, it assumes the radix to be 8 (octal numbers).</li>
<li>If the string starts with &#8220;0x&#8221;, it assumes the radix to be 16 (hexadecimal values).</li>
<li>In other cases it assumes radix as 10.</li>
</ul>
</blockquote>
<p>In the above case 010 means 8 in the octal number system.<br />
Value in Octal       Value in Decimal<br />
0                           0<br />
1                           1<br />
2                           2<br />
3                           3<br />
4                           4<br />
5                           5<br />
6                           6<br />
7                           7<br />
10                         8<br />
11                         9<br />
12                         10<br />
13                         11<br />
14                         12<br />
15                         13</p>
<p>So, to get integer 10 from string &#8220;010&#8243; always specify the base second argument.</p>
<pre class="brush:js">var value = "010";
alert(parseInt(value,10)); // correct: will alert 10</pre>
<p>So the rule of thumb is :</p>
<h3>Always specify the second parameter (radix) to parseInt function in order to get correct value.</h3>
<div class="shr-publisher-245"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.vijayjoshi.org%2F2009%2F01%2F07%2Ffaq-problem-with-javascript-function-parseint%2F' data-shr_title='FAQ+%3A+Problem+with+javascript+function+parseInt'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.vijayjoshi.org/2009/01/07/faq-problem-with-javascript-function-parseint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FAQ: calculate number of days between two dates in javascript</title>
		<link>http://www.vijayjoshi.org/2008/10/24/faq-calculate-number-of-days-between-two-dates-in-javascript/</link>
		<comments>http://www.vijayjoshi.org/2008/10/24/faq-calculate-number-of-days-between-two-dates-in-javascript/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 04:34:54 +0000</pubDate>
		<dc:creator>Vijay Joshi</dc:creator>
				<category><![CDATA[FAQ]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.vijayjoshi.org/?p=113</guid>
		<description><![CDATA[
			
				
			
		
From today onwards I am introducing a new category FAQ. It will contain quick solutions and code for common problems developers face daily in javascript and php. Browser compatibility issues specially (Firefox and IE) will also be taken care of.
So here is the first one.
Q) How can I get the difference(number of days) between two dates in javascript?
A) Date and ...]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2008%2F10%2F24%2Ffaq-calculate-number-of-days-between-two-dates-in-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.vijayjoshi.org%2F2008%2F10%2F24%2Ffaq-calculate-number-of-days-between-two-dates-in-javascript%2F&amp;source=v08i&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>From today onwards I am introducing a new category FAQ. It will contain quick solutions and code for common problems developers face daily in javascript and php. Browser compatibility issues specially (Firefox and IE) will also be taken care of.<br />
So here is the first one.</p>
<p><strong>Q)</strong> How can I get the difference(number of days) between two dates in javascript?</p>
<p><strong>A)</strong> Date and time operations in javascript can be done through the Date object. Default constructor for Date doesn&#8217;t take any argument and returns current date.</p>
<pre class="brush:js">var aDate = new Date(); // will give current date</pre>
<p>To get a specific date, you can provide year, month and day.</p>
<pre class="brush:js">var anotherDate = new Date(yyyy,mm,dd);</pre>
<p>Take care of the fact that months are from 0-11 i.e. January is 0 and December 11.<br />
Hence, new Date(2008,10,09) is 9th November 2008 not 9th October.<br />
Since there is not any inbuilt function for calculating date difference in javascript, we will use getTime() function. getTime() returns number of milliseconds since midnight of January 1, 1970.<br />
Below is the code</p>
<pre class="brush:js">var oneDay = 24*60*60*1000;	// hours*minutes*seconds*milliseconds
var firstDate = new Date(2008,01,12);
var secondDate = new Date(2008,01,22);

var diffDays = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));</pre>
<p>What we did is</p>
<ul>
<li> we took two dates</li>
<li> got milliseconds for each using getTime() function</li>
<li> calculated their difference</li>
<li> and finally divided the difference with the number of milliseconds in one day</li>
</ul>
<p>Simple, isn&#8217;t it???</p>
<div class="shr-publisher-113"></div><!-- Start Shareaholic LikeButtonSetBottom --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:right;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.vijayjoshi.org%2F2008%2F10%2F24%2Ffaq-calculate-number-of-days-between-two-dates-in-javascript%2F' data-shr_title='FAQ%3A+calculate+number+of+days+between+two+dates+in+javascript'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom -->]]></content:encoded>
			<wfw:commentRss>http://www.vijayjoshi.org/2008/10/24/faq-calculate-number-of-days-between-two-dates-in-javascript/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

