<?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>Roshan Bhattarai's Blog -  A blog about PHP, Ajax, JavaScript, CSS and Web 2.0 &#187; how-to</title>
	<atom:link href="http://roshanbh.com.np/category/how-to/feed" rel="self" type="application/rss+xml" />
	<link>http://roshanbh.com.np</link>
	<description>Useful Tutorials, Scripts , Tips, and Resources for all PHP and Ajax beginners and experts .</description>
	<lastBuildDate>Thu, 10 Jun 2010 11:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sleek and Smooth animated menu using jQuery</title>
		<link>http://roshanbh.com.np/2009/07/sleek-smooth-animated-menu-jquery.html</link>
		<comments>http://roshanbh.com.np/2009/07/sleek-smooth-animated-menu-jquery.html#comments</comments>
		<pubDate>Tue, 28 Jul 2009 09:54:55 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[animation]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=332</guid>
		<description><![CDATA[Today, I&#8217;m going to show you something interesting with jQuery. Yesterday I was thinking something to post something programming related stuff  in blog after long time and I came across a website, whose menu impressed me a lot. But checking it in a while, I found it it was built using mootools.  Since it was [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2009%2F07%2Fsleek-smooth-animated-menu-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2009%2F07%2Fsleek-smooth-animated-menu-jquery.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Today, I&#8217;m going to show you something interesting with jQuery. Yesterday I was thinking something to post something programming related stuff  in blog after long time and I came across a website, whose menu impressed me a lot. But checking it in a while, I found it it was built using mootools.  Since it was in mootools, I thought of replicating it in jQuery. I have two example of similar menu, first using jQuery core and CSS and another uses <a href="http://gsgd.co.uk/sandbox/jquery/easing/" target="_blank">jQuery easing plugin</a> to give bounce effect to the same menu.And I&#8217;ve added one more example which I though would be nice menu to show you guys.<span id="more-332"></span></p>
<p><strong><a title="sleek and smooth jquery menu" href="http://roshanbh.com.np/examples/sleek-smooth-hover-menu/" target="_blank">VIEW DEMO</a></strong></p>
<p>First of let me start, with the images which i&#8217;ve used in the background to create the first two menus.</p>
<p><img class="alignnone" style="border:none;" title="smooth jquery menu" src="http://roshanbh.com.np/examples/sleek-smooth-hover-menu/bg.png" alt="smooth jquery menu" width="192" height="25" /> and <img class="alignnone" style="border:none;" title="sleek jquery menu" src="http://roshanbh.com.np/examples/sleek-smooth-hover-menu/bg-right.png" alt="sleek jquery menu" width="8" height="25" /></p>
<p style="text-align: justify;">Please note that the please keep the left image as big as possible if you&#8217;re menu text can be long.</p>
<p style="text-align: justify;">Now, let&#8217;s look at the html code</p>
<h4>Html code for the animated jquery menu</h4>
<pre class="prettyprint" style="overflow:auto">&lt;ul class="nav" id="nav1"&gt;
   &lt;li class="first"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;Portfolio&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;About us&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;Blog&lt;/a&gt;&lt;/li&gt;
   &lt;li class="last"&gt;&lt;a href="#"&gt;Tutorials&lt;/a&gt;&lt;/li&gt;
   &lt;li class="bg"&gt;&lt;div class="left"&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p style="text-align: justify;">All the list elements are fairly simple and the list with class &#8220;<strong>bg</strong>&#8221; is the one which holds the background image for the menu. The code is same for the first and second example but for the third example we use list with class <strong>ybg </strong>instead of bg.</p>
<pre style="border: 1px solid #888888; padding: 2px;"> &lt;li class="ybg"&gt;&lt;/li&gt;</pre>
<h4>CSS code for the smooth jQuery menu</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">ul.nav {</span> <span style="color: #000080;">list-style:none;  overflow:hidden;</span>  <span style="color: #ff00ff;">}

ul.nav li {</span> <span style="color: #000080;">float:left; height:39px; background-color:#000;  padding:0 5px;</span> <span style="color: #ff00ff;"> }

ul.nav li.first {</span>
  <span style="color: #000080;">-moz-border-radius-topleft:9px; -webkit-border-top-left-radius:9px;
  -moz-border-radius-bottomleft:9px;  -webkit-border-bottom-left-radius:9px;</span>
<span style="color: #ff00ff;">}

ul.nav li.last {</span>
<span style="color: #000080;">-moz-border-radius-topright:9px; -webkit-border-top-right-radius:9px;
-moz-border-radius-bottomright:9px; -webkit-border-bottom-right-radius:9px;</span>
<span style="color: #ff00ff;">}

ul.nav li.bg {</span>
  <span style="color: #000080;"> margin:7px 0px 0px 3px; padding-right:8px; position:absolute;
   z-index:50; left:155px; width:60px; background:url(bg-right.png) no-repeat right top;</span>
<span style="color: #ff00ff;">}

ul.nav li .left {</span><span style="color: #000080;"> background:url(bg.png) no-repeat left top; height:39px; </span> <span style="color: #ff00ff;">}

ul.nav li a {</span>
  <span style="color: #000080;">padding:8px 20px;  color:#FFF; font-size:18px; font-weight:bold; display:block;
  text-decoration:none; z-index:100; position:relative;</span>
<span style="color: #ff00ff;">}

ul.nav li.ybg {</span>
  <span style="color: #000080;">background-color:#FB0; position:absolute; z-index:50;
  left:165px; width:55px; height:4px; margin-top:6px;</span>
<span style="color: #ff00ff;">}</span></pre>
<p style="text-align: justify;">As you can see there, I&#8217;ve used CSS3 rounded corners for the first and last elements of list(obviously doesn&#8217;t work IE). Furthermore, the list with class <strong>bg</strong> is used for the first and second menu examples where the image is used in the background and which moves around on mouse hover on menu with sleek effect. Please note that this list must be positioned <span style="color: #800000;">absolutely</span>.</p>
<p style="text-align: justify;">The <strong>ybg</strong> class is used for the background effect for the third menu in the example, which first moves to the menu which has current mouse position and then starts sliding down.<br />
After this, let&#8217;s get into jQuery code for providing the sleek effect for the hover menu.</p>
<h4>jQuery code for animation in the  on menu</h4>
<pre class="prettyprint" style="overflow:auto">$('#nav1 li a').hover(function()
{
  var offset=$(this).offset();
  var thiswidth =$(this).width()+13;
  $('#nav1 li.bg').stop().animate({left:offset.left+"px",width:thiswidth+"px"},600);
},
function()
{
  $('#nav1 li.bg').stop().animate({left:"155px",width:"60px"},600);
});</pre>
</p>
<p style="text-align: justify;">The above is the code for the first menu. You can see that on the hover effect of anchor, first we&#8217;ve calculated the offset of menu and also width of the anchor element. Then, finally used animate function of jQuery to move the menu and increse the width of the background to create the nice and sleek effect.</p>
<p style="text-align: justify;">As you can see the second function of hover menu, which is called when mouse is released from the anchor, just reset back the menu to it&#8217;s original position.</p>
<p style="text-align: justify;">The code is exactly same for the second menu except the following line,</p>
<pre class="prettyprint" style="overflow:auto">$('#nav3 li.bg').stop().animate({left:"155px",width:"60px"},600,'easeOutBounce');</pre>
<p style="text-align: justify;">You can see the difference easily where I&#8217;ve used <strong>easeOutBounce</strong> easing effect for the bounce out effect when mouse is released form the menu.</p>
<pre class="prettyprint">$('#nav2 li a').hover(function()
{
  var offset=$(this).offset();
  var thiswidth =$(this).width()+13;
  $('#nav2 li.ybg').stop().animate({left:offset.left+9+"px",width:thiswidth+"px"},400,function(){
     $(this).animate({height:"28px"},150);
  });
},
function()
{
   $('#nav2 li.ybg').stop().animate({height:"4px"},150,function(){
      $(this).animate({left:"165px",width:"55px"},600,'easeOutBounce');
   });
});</pre>
<p style="text-align: justify;">And you can see in the above code of the third menu, first of all the menu gets slided to the current position of menu and then the height of the background gets increased to 28px, giving a nice effect. And when mouse is released from the menu, the same things happens but in the reverse order.</p>
<p style="text-align: justify;"><strong><a title="sleek and smooth jquery menu" href="http://roshanbh.com.np/codes/sleek-smooth-hover-menu.zip">DOWNLOAD SOURCE CODE</a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=332&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2009/07/sleek-smooth-animated-menu-jquery.html/feed</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html</link>
		<comments>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:58:22 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=320</guid>
		<description><![CDATA[From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Freduce-cpu-overhead-problem-by-mysql.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Freduce-cpu-overhead-problem-by-mysql.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.<br />
<span id="more-320"></span></p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p style="text-align: justify;">We&#8217;re working on a website which was similar to <a rel="nofollow" href="http://www.swoopo.co.uk/" target="_blank">http://www.swoopo.co.uk/</a> and as you can see clearly in that website the most recent data should be fetched form MySql database in each second. in the PHP page, which was being called from Ajax every second, had around 5 SQL queries to retrieve data from server.</p>
<p>First of all, I optimized that page reducing the 5 queries into single query by using left outer joins among 3 tables. And then, I did benchmark test by using <a href="http://httpd.apache.org/docs/2.0/programs/ab.html" target="_blank">Apache benchmark tool</a>(ab) 50 request with concurrency of 50 with the following command.</p>
<blockquote><p><span style="color: #993300;">ab -n 50 -c 50 http://xyz.com/ajax_page.php</span></p></blockquote>
<p>And then in another SSH shell prompt, I run the <a href="http://linux.about.com/od/commands/l/blcmdl1_top.htm">top</a> command to view the CPU usages parallelly.</p>
<p>I was still horrified that the CPU usages by mysql after 50 concurrent user was going out of control(100%) despite of optimized query. But many joins have been used in that single query and lots of data were there in those tables so the database overhead was high even though it was a single query.</p>
<h4>How did I reduced the CPU overload drastically caused by MySql?</h4>
<p>Now, the first challenge was to reduce the database access. It was clear that it was caused by concurrent database overhead in the PHP page which was being called in every second. Here is the simple steps what I did to reduce the database overhead.</p>
<ol>
<li>I created another PHP file in which I&#8217;ve transferred the mysql query causing CPU overhead and called it from Cronjob.</li>
<li>Created a temporary table for storing the output given by  PHP page called from CronJob.</li>
<li>Then, I scheduled the CronJob in every second, don&#8217;t tell me that CronJob can&#8217;t be run less than a minute, <a href="http://www.macosxhints.com/article.php?story=20070516060214429" target="_blank">take a look at this post before saying this</a>.And from each call, the output data was stored in the temporary table.</li>
<li>And, finally from the Ajax the a new PHP page was called which was only accessing the data from temporary table with single row.</li>
</ol>
<p>I did the same benchmarking again to the newly made page(which is accessing data only from temporary table) and saw that CPU usages after the this process reduced drastically.</p>
<p>I know I can further reduce the CPU overhead by storing the temporary data in a text file. You guyz know that I&#8217;m lazy so that part is left for another day.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=320&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Model File upload overlay box using jQuery and Thickbox</title>
		<link>http://roshanbh.com.np/2008/10/model-file-upload-overlay-box-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/10/model-file-upload-overlay-box-jquery.html#comments</comments>
		<pubDate>Sat, 25 Oct 2008 18:17:02 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[modal]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=303</guid>
		<description><![CDATA[Few times back, sNare asked me how do display wordpress like overlay box where you can pass the variables when you click on the link and manipulate simultaneous actions in the overlay until user choose to close it. Today, I&#8217;ve come up with the solution of this with model upload overlay box using thickbox, a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fmodel-file-upload-overlay-box-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fmodel-file-upload-overlay-box-jquery.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Few times back, sNare asked me how do display wordpress like overlay box where you can pass the variables when you click on the link and manipulate simultaneous actions in the overlay until user choose to close it. Today, I&#8217;ve come up with the solution of this with model upload overlay box using <a href="http://jquery.com/demo/thickbox/">thickbox</a>, a jquery plugin. I&#8217;ve used the Iframe content of thickbox while displaying the box as modal box.</p>
<p><span id="more-303"></span><br />
<strong><a href="http://roshanbh.com.np/examples/file-upload-overlay-jquery" target="_blank">LIVE DEMO </a></strong></p>
<h4>How to use the thickbox as modal overlay box?</h4>
<p>Let&#8217;s look at the step by step to use thickbox for passing variables.</p>
<p>First of all, we have to include jQuery JavaScript Library to our page,</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;</pre>
<p>After this, include the <a href="http://jquery.com/demo/thickbox/">thickbox</a> plugin of jQuery,</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript" src="thickbox-compressed.js"&gt;&lt;/script&gt;</pre>
<p>There is a CSS for using thickbox which also need to linked to the current page,</p>
<pre class="prettyprint" style="overflow:auto">&lt;link rel="stylesheet" href="thickbox.css" type="text/css" media="screen" /&gt;</pre>
<p>Now, let&#8217;s look at the anchor tag which passes the variables to overlay box and keep the overlay at top no matter how many simultaneous accesses occur in the box.</p>
<pre class="prettyprint" style="overflow:auto">&lt;a href="file_upload.php?post_id=5&amp;TB_iframe=true&amp;height=200&amp;width=300&amp;modal=true" class="thickbox" &gt;&lt;strong&gt;Upload Files&lt;/strong&gt;&lt;/a&gt;</pre>
<p>If you want to know how to use the thickbox, then you can checkout their home page which contains good documentation. The main point is, <span style="color: #000080;">class=&#8217;thickbox&#8217; </span>must be used for the displaying the content in overlay.</p>
<h4>How to pass variables to overlay box (thickbox)?</h4>
<p>If you look at the href attribute of anchor tag, you can see clearly that I&#8217;ve passed <span style="color: #003366;">post_id</span> variable with value <span style="color: #003366;">5</span> to <span style="color: #000080;">file_upload.php</span>, which can be easily fetched from PHP using <span style="color: #000080;">$_GET['post_id']</span>.</p>
<h4>How to make overlay box stay opened on simultaneous access?</h4>
<p>Now this is part which many people has asked me how to do it. To use thickbox in this fashion, you&#8217;ve to use it in iframe content mode.The following property of thickbox make it remained open on simultaneous access,</p>
<pre class="prettyprint" style="overflow:auto">TB_iframe=true</pre>
<p>Furthermore, We&#8217;ve used the following property to display the overlay box as modal box.</p>
<pre class="prettyprint" style="overflow:auto">modal=true</pre>
<p><strong><a href="http://roshanbh.com.np/codes/file-upload-overlay-jquery.zip">DOWNLOAD SOURCE CODE </a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=303&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/10/model-file-upload-overlay-box-jquery.html/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>jQuery plugin: word-counter for textarea</title>
		<link>http://roshanbh.com.np/2008/10/jquery-plugin-word-counter-textarea.html</link>
		<comments>http://roshanbh.com.np/2008/10/jquery-plugin-word-counter-textarea.html#comments</comments>
		<pubDate>Mon, 20 Oct 2008 11:43:50 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[jquery plugin]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=299</guid>
		<description><![CDATA[Sorry friends on the way of move to new home I&#8217;ve been lost from the blog as I didn&#8217;t have internet connection for few last weeks. Now, I&#8217;m back and I try to be regular as much as I can. Inspired from the new feature of wordpress 2.6.x which displays word count of each post, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fjquery-plugin-word-counter-textarea.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fjquery-plugin-word-counter-textarea.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Sorry friends on the way of move to new home I&#8217;ve been lost from the blog as I didn&#8217;t have internet connection for few last weeks. Now, I&#8217;m back and I try to be regular as much as I can. Inspired from the new feature of wordpress 2.6.x which displays word count of each post, I&#8217;ve developed jQuery plugin to display word-count of Textarea. Please note that it is <span style="color: #000080;">word count plugin</span> not <span style="text-decoration: line-through;">character counter</span>.<br />
<span id="more-299"></span><br />
<a href="http://roshanbh.com.np/examples/jquery-word-count-plugin/" target="_blank"><strong>LIVE  DEMO </strong></a></p>
<h4>Jquery plugin: Word-count code</h4>
<pre class="prettyprint" style="overflow:auto">jQuery.fn.wordCount = function(params)
{
   var p =  {
   counterElement:"display_count"
   };
   var total_words;

  if(params) {
      jQuery.extend(p, params);
   }

  //for each keypress function on text areas
  this.keypress(function()
  {
    total_words=this.value.split(/[\s\.\?]+/).length;
    jQuery('#'+p.counterElement).html(total_words);
   });
};</pre>
<p><a href="http://roshanbh.com.np/codes/jquery.wordcount.js" target="_blank"><strong>VIEW PLUGIN&#8217;S CODE</strong></a></p>
<p>As you can in the above code, I assume that each words of a paragraph are separated by the either spaces or dots(.) . Please have your suggestion if i can more characters to improve this plugin.</p>
<h4>How to use this plugin?</h4>
<p>Well, you can guess that a Textarea is needed of whose words are counted and another element like div or span needed to display the word count.</p>
<p>For example, the below HTML code contains Textarea (whose total word is counted) and span (for displaying counted word).</p>
<pre class="prettyprint" style="overflow:auto">&lt;textarea name="word_count" id="word_count" cols="30" rows="6"&gt;&lt;/textarea&gt;
Total word Count : &lt;span id="display_count"&gt;0&lt;/span&gt;</pre>
<p>Remember that the id of text area is &#8220;<span style="color: #000080;">word_coun</span>t&#8221; and &#8220;<span style="color: #000080;">display_count</span>&#8220;.</p>
<p>Now, let look at the jQuery code for displaying word count of text area , note that we are calling the function wordCount() which we&#8217;ve just developed in the plugin of jQuery.</p>
<pre class="prettyprint">$('#word_count').wordCount();</pre>
<p><strong>Note: </strong>display_count  is default id of element which is already defined in the plugin if you want to use the different id of elment then you&#8217;ve to override the value of variable <strong>counterElement</strong> which contains the <span style="color: #000080;">id</span> of element displaying word count.</p>
<pre class="prettyprint">$('#word_count').wordCount({counterElement:"word_counter"});</pre>
<p><a href="http://roshanbh.com.np/codes/jquery-word-count.zip"><strong>DOWNLOAD EXAMPLE CODE </strong></a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=299&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/10/jquery-plugin-word-counter-textarea.html/feed</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Creating and Parsing JSON data with PHP</title>
		<link>http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html</link>
		<comments>http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html#comments</comments>
		<pubDate>Sat, 04 Oct 2008 18:10:51 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=293</guid>
		<description><![CDATA[Yesterday, I was in a party and a guy came near to me and asked me what is JSON and how can handle it via PHP. Today, I&#8217;m going to tell you something about JSON data and how we can handle them via PHP. Although, JSON stands JavaScript Object Notation, it is used by many [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fcreating-parsing-json-data-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fcreating-parsing-json-data-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday, I was in a party and a guy came near to me and asked me what is JSON and how can handle it via PHP. Today, I&#8217;m going to tell you something about JSON data and how we can handle them via PHP. Although, JSON stands <strong><a href="http://www.json.org/" target="_blank">JavaScript Object Notation</a></strong>, it is used by many other technologies like PHP and Java for data interchange format over the Internet.</p>
<p><span id="more-293"></span></p>
<h4>What is JSON?</h4>
<p style="text-align: justify;">JSON is ultra-weight data interchange data format used over the internet for transferring the data. While XML is a dominant data interchange format over the internet but JSON is less complex and light-weight data.</p>
<p style="text-align: justify;">Though it was first made to be used with JavaScript for accessing remote data, it is now used by many other languages because JSON data is platform independent data format.</p>
<h4>Data Types and Example of JSON data</h4>
<p>JSON supports various kind of data types which included numbers, strings, booleans as well as array datas and obviously object (collection of key:value pairs, comma-separated and enclosed in curly brackets).</p>
<p>Now, let&#8217;s look at the example of simple format of JSON data for a detail of a employee,</p>
<pre class="prettyprint" style="overflow:auto">{"id":"1","name":"mike","country":"usa","office":["microsoft","oracle"]}</pre>
<h4>Creating and Parsing JSON data format in PHP</h4>
<p>To handle JSON data there is <a href="http://www.php.net/json" target="_blank">JSON extension</a> in PHP which is aviable after PHP 5.2.0. Two funcitons : <a href="http://www.php.net/manual/en/function.json-encode.php">json_encode()</a> and <a href="http://www.php.net/manual/en/function.json-decode.php">json_decode()</a> are very useful converting and parsing JSON data through PHP.</p>
<p>First of all, let&#8217;s look at the PHP code to create the JSON data format of above example using array of PHP.</p>
<pre class="prettyprint" style="overflow:auto">$json_data = array ('id'=&gt;1,'name'=&gt;"mike",'country'=&gt;'usa',"office"=&gt;array("microsoft","oracle"));
echo json_encode($json_data);</pre>
<p>The above code generates the JSON data exactly as above. Now, let&#8217;s decode above JSON data in PHP.</p>
<pre class="prettyprint" style="overflow:auto">$json_string='{"id":1,"name":"mike","country":"usa","office":["microsoft","oracle"]} ';
$obj=json_decode($json_string);</pre>
<p>Now, the $obj variable contains JSON data parsed in PHP object which you can display using code below.</p>
<pre class="prettyprint" style="overflow:auto">echo $obj-&gt;name; //displays mike
echo $obj-&gt;office[0]; //displays microsoft</pre>
<p>As you can guess,$obj-&gt;office is an array and you can loop through it using <a href="http://www.php.net/foreach" target="_blank">foreach</a> loop of PHP,</p>
<pre class="prettyprint" style="overflow:auto">foreach($obj-&gt;office as $val)
    echo $val;</pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=293&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html/feed</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Getting random number between range of two numbers in JavaScript</title>
		<link>http://roshanbh.com.np/2008/09/get-random-number-range-two-numbers-javascript.html</link>
		<comments>http://roshanbh.com.np/2008/09/get-random-number-range-two-numbers-javascript.html#comments</comments>
		<pubDate>Tue, 30 Sep 2008 10:36:26 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[random number]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=291</guid>
		<description><![CDATA[Yesterday, Steve asked me how can we have random number function in JavaScript like rand() function of PHP where the programmer can specify the range of two numbers within which we need the random number. Today, I&#8217;m going to share two functions in JavaScript, In first function , you can specify the number and the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fget-random-number-range-two-numbers-javascript.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fget-random-number-range-two-numbers-javascript.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday, Steve asked me how can we have random number function in JavaScript like rand() function of PHP where the programmer can specify the range of two numbers within which we need the random number. Today, I&#8217;m going to share two functions in JavaScript, In first function , you can specify the number and the function generate the random number between 1 and N. In another JavaScript function, you can specify range of two numbers between which you&#8217;ve to get a random number. Furthermore, there is optional last parameter in these function for decimal places, if provided, will return the random number with the decimal places specified in the third parameter.<br />
<span id="more-291"></span></p>
<h4>Getting random number in JavaScript</h4>
</p>
<p style="text-align: justify;">Getting random number is very easy you can use JavaScript function random() of Math object to get the random number between 0 and 1. For example, above JavaScript statement returns a random number between 0 and 1.</p>
<pre class="prettyprint">alert(Math.random()); // returns number like 0.3871769046200184</pre>
<h4>JavaScript function to get random number between 1 and N</h4>
<pre class="prettyprint" style="overflow:auto">//function to get random number from 1 to n
function randomToN(maxVal,floatVal)
{
   var randVal = Math.random()*maxVal;
   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}</pre>
<p style="text-align: justify;">As, you can see in the above JavaScript function, there are two parameters. One for the maximum value(N) up to which random number have to be generated. The second parameter is optional which specifies number of digits after decimal point.If not provided, this function returns integer.</p>
<h4>JavaScript function to get random number between a range</h4>
<pre class="prettyprint" style="overflow:auto">//function to get random number upto m
function randomXToY(minVal,maxVal,floatVal)
{
  var randVal = minVal+(Math.random()*(maxVal-minVal));
  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}</pre>
<p style="text-align: justify;">The above JavaScript funciton accepts three parameters.The first and second parameter is mandatory while the third is optional. The first and second parameter specifies the range between which the random number has to be generated. The thir parameter is optional which specifies number of floating point digits, if not provided, the above JavaScript function returns integer random number.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=291&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/get-random-number-range-two-numbers-javascript.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Table row manipulation using jQuery JavaScript</title>
		<link>http://roshanbh.com.np/2008/09/table-row-manipulation-jquery-javascript.html</link>
		<comments>http://roshanbh.com.np/2008/09/table-row-manipulation-jquery-javascript.html#comments</comments>
		<pubDate>Thu, 18 Sep 2008 06:33:27 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=277</guid>
		<description><![CDATA[In a jQuery tutorial, I&#8217;ve shown how to display different color in alternate row of table using jQuery. This time I&#8217;ve come up with advanced version of same tutorial where you can add different color in alternate row of table whereas you can display a different color when mouse moves over each row of table [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Ftable-row-manipulation-jquery-javascript.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Ftable-row-manipulation-jquery-javascript.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In a jQuery tutorial, I&#8217;ve shown how to display <a href="http://roshanbh.com.np/2008/03/different-color-alternate-row-jquery.html">different color in alternate row of table using jQuery</a>. This time I&#8217;ve come up with advanced version of same tutorial where you can add different color in alternate row of table whereas you can display a different color when mouse moves over each row of table furthermore you can assign a different color to table row when mouse is clicked in the table row.</p>
<p style="text-align: justify;"><span id="more-277"></span><a href="http://roshanbh.com.np/examples/table-manipulation-jquery/" target="_blank"><br />
<strong>View Live Demo</strong></a></p>
<h4>HTML code for table row filtering using jQuery</h4>
<pre class="prettyprint" style="overflow:auto">&lt;table id="mytable" border="0" width="40%"&gt;
  &lt;tr&gt;&lt;td&gt;Michael&lt;/td&gt;&lt;td&gt;21&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Sam&lt;/td&gt;&lt;td&gt;22&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</pre>
<p>As you can see there is nothing special in the above code where I&#8217;ve  defined a table with id &#8220;mytable&#8221;.</p>
<h4>CSS code for table row manipulation</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">.oddtr
{</span>
	<span style="color: #000080;">background-color:#EFF1F1;</span>
<span style="color: #ff00ff;">}
.eventr
{</span>
	<span style="color: #000080;">background-color:#F8F8F8;</span>
<span style="color: #ff00ff;">}
.trover
{</span>
	<span style="color: #000080;">background-color: #0099CC;</span>
<span style="color: #ff00ff;">}
.trclick
{</span>
	<span style="color: #000080;">background-color: #00CCCC;</span>
<span style="color: #ff00ff;">}</span></pre>
<p>As you can above code, I&#8217;ve defined four different classes with four different color. <span style="color: #000080;">oddtr</span> for coloring the odd row of table, similarly <span style="color: #000080;">eventr</span> for even row of table then <span style="color: #000080;">trover</span> class for displaying different color when mouse moves over the table row i.e on mouse over event. Finally, <span style="color: #000080;">trclick</span> class for displaying different color of the row when mouse is clicked in the table row. Note that you can change these colors according to your choice.</p>
<h4>jQuery&#8217;s JavaScript code for table row manipulation</h4>
<pre class="prettyprint" style="overflow:auto">//these two line adds the color to each different row
$("#mytable tr:even").addClass("eventr");;
$("#mytable tr:odd").addClass("oddtr");;
//handle the mouseover , mouseout and click event
$("#mytable tr").mouseover(function() {$(this).addClass("trover");}).mouseout(function() {$(this).removeClass("trover");}).click(function() {$(this).toggleClass("trclick");});</pre>
<p>The first two line of jQuery adds two differnt classes to the alternate rows of  table with id &#8220;<span style="color: #000080;">mytable</span>&#8220;. The last line of jQuery acts for three differnt on the table row. When mouse is moved over the table row <span style="color: #000080;">trover</span> class is added to that table row. When mouse moves away form that table row trover class is removed from that particular row and finally when mouse is clicked on tha particular row it toggles the class <span style="color: #000080;">trclick</span> on that particular row.</p>
<p><a href="http://roshanbh.com.np/codes/table-manipulation-jquery.zip" target="_blank"><strong>Download Full Source Code</strong></a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=277&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/table-row-manipulation-jquery-javascript.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Solving European characters (Western charset) problem with Ajax and PHP</title>
		<link>http://roshanbh.com.np/2008/09/solving-european-characters-western-charset-problem-with-ajax-and-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/solving-european-characters-western-charset-problem-with-ajax-and-php.html#comments</comments>
		<pubDate>Mon, 15 Sep 2008 18:32:20 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[ajax problem]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=276</guid>
		<description><![CDATA[Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on the western characters(European charset).Lots of people asked me about this problem where these European charset is displayed in unreadable format after fetching it from ajax. Problem with European Charset with [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fsolving-european-characters-western-charset-problem-with-ajax-and-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fsolving-european-characters-western-charset-problem-with-ajax-and-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on the western characters(European charset).Lots of people asked me about this problem where these European charset is displayed in unreadable format after fetching it from ajax.<br />
<span id="more-276"></span></p>
<h4>Problem with European Charset with Ajax and PHP</h4>
<p>Suppose that I&#8217;ve the following code in PHP file, which output the string which contain the european characters.</p>
<pre class="prettyprint" style="overflow:auto">&lt;?php
  $str="€-accentuée";
  echo $str;
?&gt;</pre>
<p>Now, let&#8217;s use the Ajax from JavaScript using Jquery Code to fetch the data from PHP.</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript"&gt;
$(function()
{
  $('#charsetdiv').load("test2.php");
});
&lt;/script&gt;
&lt;div id="charsetdiv"&gt;&lt;/div&gt;</pre>
<p>If you&#8217;ve not used jQuery then you might be wondering about the ajax code, you can check the <a href="http://roshanbh.com.np/2008/03/jquery-benefits-examples-free-ebook.html">benefits of jquery</a> from this post and download <a href="http://roshanbh.com.np/2008/03/jquery-benefits-examples-free-ebook.html">free ebook of jQuery</a>.</p>
<p>After getting value from Ajax, the division with id &#8220;charsetdiv&#8221;, let&#8217;s look at the output.</p>
<pre class="prettyprint" style="overflow:auto">?-accentu?e</pre>
<h4>Solving western Character Set problem with Ajax and PHP</h4>
<p style="text-align: justify;">The above problem is occurred because of not defining proper charset to these European characters. We can solve this problem by sending the header which define the appropriate Character Set for these characters.Let&#8217;s see, how I solve this problem just adding the header which define the charset Windows-1256 &#8211; which support Arabic as well as European characters.</p>
<pre class="prettyprint" style="overflow:auto">&lt;?php
  header("Content-Type: text/html; charset=Windows-1256\n");
  $str="€-accentuée";
  echo $str;
?&gt;</pre>
<p>After adding that header in PHP, you&#8217;ll get the appropriate european characters in  your Ajax enabled application.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=276&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/solving-european-characters-western-charset-problem-with-ajax-and-php.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Changing textbox value from dropdown list using Ajax and PHP</title>
		<link>http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html#comments</comments>
		<pubDate>Thu, 04 Sep 2008 19:10:00 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=253</guid>
		<description><![CDATA[Yesterday Tarquin macey asked me how can we change the value of the textbox based using Ajax and PHP based on the changing value of the dropdown list.Today, I&#8217;ve come up with a solution from him.In this post, you&#8217;ll see how to get the currency code of a country from PHP using Ajax and this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fchange-textbox-value-dropdown-list-ajax-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fchange-textbox-value-dropdown-list-ajax-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday   <a href="http://www.tarquinm.com/" target="_blank">Tarquin macey</a> asked me how can we change the value of the textbox based using Ajax and PHP based on the changing value of the dropdown list.Today, I&#8217;ve come up with a solution from him.In this post, you&#8217;ll see how to get the currency code of a country from PHP using Ajax and this currency code will replace the value of textbox each time the dropdown list changes.</p>
<p><span id="more-253"></span></p>
<p><strong><a href="http://roshanbh.com.np/examples/dropdown-textbox-ajax" target="_blank">View Live Demo</a> </strong></p>
<h4>Writing Code for changing textbox value from dropdown list using Ajax and PHP</h4>
<p>After looking at the above demo, let&#8217;s start writing code for the changing the currency code value in the textbox form Ajax using PHP when you changes the country from the dropdown list.</p>
<p><strong>HTML Code</strong></p>
<pre class="prettyprint" style="overflow:auto">&lt;select name="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)"&gt;
 &lt;option value=""&gt;Select Country&lt;/option&gt;
	&lt;option value="1"&gt;USA&lt;/option&gt;
	&lt;option value="2"&gt;UK&lt;/option&gt;
	&lt;option value="3"&gt;Nepal&lt;/option&gt;
&lt;/select&gt;
&lt;input type="text" name="cur_code" id="cur_code" &gt;</pre>
<p>As you can in the above code, there are two main components one dropdown list whose name is country and contains the list country in it.The JavaScript function <span style="color: #000080;"><span class="prettyprint" style="overflow:auto">getCurrencyCode</span>()</span> is called when user change value in the list. Note down the name and id of textbox which will have the currency code fetched from Ajax.</p>
<p><strong>JavaScript Code for changing textbox value without refreshing the page<br />
</strong></p>
<pre class="prettyprint" style="overflow:auto">function getCurrencyCode(strURL)
{
  var req = getXMLHTTP();
  if (req)
  {
	//function to be called when state is changed
	req.onreadystatechange = function()
	{
  	  //when state is completed i.e 4
	  if (req.readyState == 4)
	  {
		// only if http status is "OK"
		if (req.status == 200)
		{
			document.getElementById('cur_code').value=req.responseText;
		}
		else
		{
			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
		}
	  }
        }
	req.open("GET", strURL, true);
	req.send(null);
  }
}</pre>
<p style="text-align: justify;">In the first line of the above code, the XMLHTTPRequest object is created using getXMLHTTP() function. To look at the the structure of this function, take a look at this old post <a href="http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-and-php.html">change the value of dropdown list using Ajax and PHP</a> . After checking the appropriate value of <span style="color: #000080;">readystate</span>(4 means completed) and <span style="color: #000080;">status</span>(200 means ok) property of XMLHTTPRequest object, the value of textbox is replaced with the returned value from PHP using Ajax . The response ,which is can be accessed via <span class="prettyprint" style="overflow:auto">req.responseText property, is written to textbox via the value property of textbox. </span></p>
<p><strong>PHP code for changing the value of textbox using Ajax and PHP </strong></p>
<pre class="prettyprint" style="overflow:auto">&lt;?php
$country=$_REQUEST['country'];
switch($country)
{
	case "1" :
		echo "USD";
		break;
	case "2" :
		echo "GBP";
		break;
	case "3" :
		echo "NPR";
		break;
}
?&gt;</pre>
<p style="text-align: justify;">As you can see the above PHP code, it is fairly simple which just print the currency code value according to the name of country. The value which is in the echo statement is going to returned from PHP via Ajax.</p>
<p><strong><a href="http://roshanbh.com.np/codes/dropdown-textbox-ajax.zip" target="_blank">Download Full Source Code </a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=253&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Force download multiple files in a zip archive using PHP</title>
		<link>http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html#comments</comments>
		<pubDate>Tue, 02 Sep 2008 16:44:13 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[zip php]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=247</guid>
		<description><![CDATA[In this post, I&#8217;ll show you how can you download the multiples files in a zip archive using PHP. I&#8217;ve made a function in PHP where you&#8217;ve to pass the parameters the array of files to be zipped, the second parameter is file name as which zip archive file has to be downloaded and finally [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fforce-download-mutiple-files-zip-archive-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fforce-download-mutiple-files-zip-archive-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">In this post, I&#8217;ll show you how can you download the multiples files in a zip archive using PHP. I&#8217;ve made a function in PHP where you&#8217;ve to pass the parameters the array of files to be zipped, the second parameter is file name as which zip archive file has to be downloaded and finally the path of files where files to be zipped are located.(assuming that they are all in same folder)</p>
<p><span id="more-247"></span></p>
<h4>PHP function to download mutiple files in a zip archive</h4>
<pre class="prettyprint" style="overflow:auto">//function to zip and force download the files using PHP
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
  //create the object
  $zip = new ZipArchive();
  //create the file and throw the error if unsuccessful
  if ($zip-&gt;open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
    exit("cannot open &lt;$archive_file_name&gt;\n");
  }

  //add each files of $file_name array to archive
  foreach($file_names as $files)
  {
    $zip-&gt;addFile($file_path.$files,$files);
  }
  $zip-&gt;close();

  //then send the headers to foce download the zip file
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=$archive_file_name");
  header("Pragma: no-cache");
  header("Expires: 0");
  readfile("$archive_file_name");
  exit;
}</pre>
<p style="text-align: justify;"><a href="http://roshanbh.com.np/examples/force-download-zip-php.phps" target="_blank"><strong>Download Source code</strong></a></p>
<p style="text-align: justify;">In the above PHP function, first of all the object of ZipArchive class. Remember that this library is bundled in PHP after the version of PHP 5.2 only.If you&#8217;re using the PHP version older than that one then you&#8217;ve to get it from PECL extension.</p>
<p style="text-align: justify;">After that, we&#8217;ve tried to create the zip arhive with the open() function using the ZIPARCHIVE::CREATE flag.After successfully creating the archive, each files whose names are passed as array are added to zip file using addFile() function of ZipArchive() class.Then, this zip archive is closed using close() function of same class.</p>
<p style="text-align: justify;">And, finally different headers are passed through PHP to force download the newly created zip file.</p>
<h4>Example of Using Above PHP function</h4>
<pre class="prettyprint" style="overflow:auto">  $file_names=array('test.php','test1.txt');
  $archive_file_name='zipped.zip';
  $file_path=dirname(__FILE__).'/';
  zipFilesAndDownload($file_names,$archive_file_name,$file_path);</pre>
<p>The above PHP function call is straighforward and after calling that function you&#8217;ll get the zip archive containing mutiple files passed as array in the first parameter of the function.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=247&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html/feed</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Choosing the best among the web hosting providers</title>
		<link>http://roshanbh.com.np/2008/09/choosing-best-web-hosting-providers.html</link>
		<comments>http://roshanbh.com.np/2008/09/choosing-best-web-hosting-providers.html#comments</comments>
		<pubDate>Tue, 02 Sep 2008 16:15:50 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[website review]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web hosting]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=248</guid>
		<description><![CDATA[You&#8217;ll be in a great confusion if you have to buy the service from a new web hosting provider. There are many web hosting providers in the market and you&#8217;ve to choose the best among them so that you&#8217;ll not be suffered by choosing it. Most of the customers suffers from bad web hosting companies [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fchoosing-best-web-hosting-providers.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fchoosing-best-web-hosting-providers.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">You&#8217;ll be in a great confusion if you have to buy the service from a new web hosting provider.  There are many web hosting providers in the market and you&#8217;ve to choose the best among them so that you&#8217;ll not be suffered by choosing it. Most of the customers suffers from bad web hosting companies due to their unreliability and lacking of sustainability in the high volume of traffic.So, I always suggest you to compare the features of web hosting providers before buying it.</p>
<p><span id="more-248"></span></p>
<h4>How to compare and get suitable web hosting provider?</h4>
<p>There are many web hosting review and rating websites where you can find the information and review among the good web hosting providers. You can compare the features among the leading hosting providers in market. If you want to find the comparison among the different leading web hosting providers then you can view this <a href="http://webhostingrating.com">web hosting rating</a> website.webhostingratings.com is a new web hosting rating website where they are trying to build one of the biggest web hosting provider guide.</p>
<p style="text-align: justify;">How to find a suitable web hosting plan? The answer of this question is a bit complicated. It depends upon the requirement of you and your websites.For example, if you have a web development company then what kind of web hosting plan will you buy ? My answer would be Reseller Hosting Providers as I can sell the web spaces among my customers where I act like a secondary web hosting provider. You can also buy Shared hosting or Virtual Private hosting(VPS) depending upon your requirement. If you want to know more about them then you can check the <a href="http://webhostingrating.com/articles/">web hosting tutorials</a> from webhostingratings.com.</p>
<h4>Things you&#8217;ve to care about before choosing a web hosting provider</h4>
<p>Here are the list of things you have to care about before choosing a web hosting provider.</p>
<ol>
<li><strong>Web Space</strong> &#8211; What is the size of space they are providing at the give cost ? Is is cheaper than others?</li>
<li><strong> Bandwidth</strong> &#8211; What is the limitation of bandwidth(data transfer allowed) per month allowed? Is is enough for you per month ? Is it better than the other web hosting providers?</li>
<li><strong>Uptime</strong> &#8211; Uptime measure weather the given web hosting provider is reliable or not. For example, 99% uptime tells that you&#8217;re going to get hassle for 1 minute in every 100 minute. Is that web hosting provider has the uptime of 99.99% or not?</li>
<li><strong>Awards</strong> &#8211; Weather the web hosting providers you&#8217;re going to choose has got any <a href="http://webhostingrating.com/awards/">web hosting awards</a> for their excellent service or not. This measure also justify their excellency about the service.</li>
</ol>
<p style="text-align: justify;">These are the most basic things you&#8217;ve to look after before choosing the best web hosting provider.So, if you&#8217;ve to buy a web hosting provider then I recommend to read the reviews and their features from <a href="http://webhostingrating.com/">http://webhostingrating.com</a> .</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=248&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/choosing-best-web-hosting-providers.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Handling array of HTML Form Elements in JavaScript and PHP</title>
		<link>http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html</link>
		<comments>http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html#comments</comments>
		<pubDate>Wed, 27 Aug 2008 19:46:30 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=240</guid>
		<description><![CDATA[Today, I would like to share the way of handling array of HTML FORM elements using JavaScript and PHP.Well, it&#8217;s very easy to get the data from the array of HTML form elements in PHP and using them but in JavaScript it&#8217;s a bit tricky to handle the array of HTML form elements. I had [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fhandling-array-html-form-elements-javascript-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fhandling-array-html-form-elements-javascript-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Today, I would like to share the way of handling array of HTML FORM elements using JavaScript and PHP.Well, it&#8217;s very easy to get the data from the array of HTML form elements in PHP and using them but in JavaScript it&#8217;s a bit tricky to handle the array of HTML form elements. I had a hard time to handle them via JavaScript in past thats why I&#8217;m posting it here so that people will not have hard time to cope with array of form elements in JavaScript and PHP.</p>
<p><span id="more-240"></span></p>
<h4>Array of HTML form elements</h4>
<p style="text-align: justify;">You can create the array of Form Elements for grouping the similar kind of object or data. The array of elements are very useful in the context where you don&#8217;t know how many similar kind of data user have to enter. For example, you have a form where user have to enter his education qualification then you might not know how many of the textboxes are required for a person and in such kind situation you can dynamically generate array of the elements in the form for entering such kind of information.</p>
<pre class="prettyprint" style="overflow:auto">&lt;input name="education[]" type="text" size="20" maxlength="40" /&gt;
&lt;input name="education[]" type="text" size="20" maxlength="40" /&gt;
&lt;input name="education[]" type="text" size="20" maxlength="40" /&gt;</pre>
<p>As you can in the above code, there are array element of textbox defined with the name &#8220;education&#8221;.Now, let&#8217;s see how can we handle them via JavaScript and PHP.</p>
<h4>How to handle array of HTML form elements using PHP</h4>
<p style="text-align: justify;">If you submit the the the form with the above the array of elements then you can assess it via array of $_POST['education'] in PHP. You can use foreach() loop to access the value of the value of these form elements via PHP.</p>
<pre class="prettyprint" style="overflow:auto">foreach($_POST['education'] as $key=&gt;$value)
 echo $key.' '.$value;</pre>
<p style="text-align: justify;">Normally, posted variable are contained within the POST array but when you post the array of Form Elements then at that time the values are contained within the array of array i.e within $_POST['education'] in above exmaple.</p>
<h4>How to handle array of Form elements using JavaScript</h4>
<p style="text-align: justify;">Handling the array of Form element part is a bit tricky. Now, let try to access the values of the above elements using JavaScript. First, let&#8217;s store the above object in a JavaScript variable</p>
<pre class="prettyprint" style="overflow:auto">var mutli_education = document.form_name.elements["education[]"];</pre>
<p style="text-align: justify;">After storing the object in the variable, we can access the individual variables in the following way in JavaScript</p>
<pre class="prettyprint">for(i=0;i&lt;mutli_education.length;i++)
{
 alert(mutli_education[i].value);
}</pre>
<p style="text-align: justify;">As you can see, you can get how many elements are there in the array using the <span style="color: #000080;">lengh </span>property and you can use the <span style="color: #000080;">value</span> property to get the value of the indivisual element.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=240&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Move an object on mouse wheel scroll event using JavaScript</title>
		<link>http://roshanbh.com.np/2008/08/move-object-mouse-wheel-scroll-event-javascript.html</link>
		<comments>http://roshanbh.com.np/2008/08/move-object-mouse-wheel-scroll-event-javascript.html#comments</comments>
		<pubDate>Tue, 19 Aug 2008 08:27:34 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=226</guid>
		<description><![CDATA[Today, I&#8217;ve come along with another post where you&#8217;ll see how to move a object within web page when you scroll the mouse wheel using JavaScript.In this example, when you move the mouse wheel the object i.e div moves upwards or downwards depending upon the scrolling direction the mouse wheel. Now, let&#8217;s look at the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fmove-object-mouse-wheel-scroll-event-javascript.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fmove-object-mouse-wheel-scroll-event-javascript.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Today, I&#8217;ve come along with another post where you&#8217;ll see how to move a object within web page when you scroll the mouse wheel using JavaScript.In this example, when you move the mouse wheel the object i.e <strong>div </strong>moves upwards or downwards depending upon the scrolling direction the mouse wheel. Now, let&#8217;s look at the detail of this tutorial in JavaScript.</p>
<p><span id="more-226"></span></p>
<h4><a href="http://roshanbh.com.np/examples/mouse-wheel.html" target="_blank">View Live Demo</a></h4>
<h4>HTML and CSS for object to be scrolled on mouse wheel movement</h4>
<pre class="prettyprint" style="overflow:auto ">&lt;div id="object"&gt;This block moves as you move mouse wheel.&lt;/div&gt;</pre>
<p style="text-align: justify;">As you can see above code, the object which is going to be moved is placed in the division with id <strong>object</strong>. For the above division, I&#8217;ve defined style and you can see the CSS code below. Remember that ,you can change the below CSS code according to your need but remember that the position should be <strong>absolute</strong>.</p>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">#object {</span>
<span style="color: #333399;">font-weight:bold;
background:yellow;
padding:5px;
width:300px;
position:absolute;
left:500px;
top:200px;</span>
<span style="color: #ff00ff;">}</span></pre>
<h4>JavaScript code for handling mouse scroll event.</h4>
<pre class="prettyprint" style="overflow:auto ">window.onload = function()
{
  //adding the event listerner for Mozilla
  if(window.addEventListener) document.addEventListener('DOMMouseScroll', moveObject, false);
  //for IE/OPERA etc
  document.onmousewheel = moveObject;
}</pre>
<p>First of all, we need to attach the mouse wheen scroll event to the document.As you can see in the first line of above function,  event listner &#8220;moveObject&#8221; is added to the mouse scroll event in the document for Mozilla browsers and in the second line event handler &#8220;moveObject&#8221; is called for <strong>document.onmousewheel</strong> event for browsers like IE and Opera etc.</p>
<p>Now look at the mouse wheel scroll event handler function &#8220;moveObject&#8221;</p>
<pre class="prettyprint" style="overflow:auto ">function moveObject(event)
{
  var delta = 0;
  if (!event) event = window.event;
  // normalize the delta
  if (event.wheelDelta)
  {
    // IE &amp; Opera
   delta = event.wheelDelta / 120;
  }
  else if (event.detail) // W3C
  {
    delta = -event.detail / 3;
  }
  var currPos=document.getElementById('object').offsetTop;
  //calculating the next position of the object
  currPos=parseInt(currPos)+(delta*10);
  //moving the position of the object
  document.getElementById('object').style.top=currPos+"px";
}</pre>
<p style="text-align: justify;">As you can see in the above function first the scrolling <strong>delta</strong> value is calculated. The delta variable holds the value  -1 or 1 depending upon the movement of the wheel.</p>
<p style="text-align: justify;">After calculating the detail value, the top offset of the object is taken using <strong>offsetTop</strong> property using JavaScript. After that, the next position of the object is calculated, which is 10 pixel up or down from the current position of the object.</p>
<p style="text-align: justify;">Finally, style.top property is used to set the current position of the object using JavaScript.</p>
<h4><a href="http://roshanbh.com.np/codes/mouse-wheel.zip" target="_blank">Download Full Source Code </a></h4>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=226&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/move-object-mouse-wheel-scroll-event-javascript.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to hide actual URL in the status bar of all browsers?</title>
		<link>http://roshanbh.com.np/2008/08/different-status-bar-text-hyperlink-mouseover.html</link>
		<comments>http://roshanbh.com.np/2008/08/different-status-bar-text-hyperlink-mouseover.html#comments</comments>
		<pubDate>Sat, 09 Aug 2008 17:50:46 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[status-bar]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=210</guid>
		<description><![CDATA[Yesterday, Jacob mailed me and asked me how can I show different text or link in the status bar of browsers like Firefox or safari when mouse is over the link.He found the technique which only worked for IE but not for other browser but I&#8217;ve come up with a technique which works for all [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fdifferent-status-bar-text-hyperlink-mouseover.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fdifferent-status-bar-text-hyperlink-mouseover.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday, Jacob mailed me and asked me how can I show different text or link in the status bar of browsers like Firefox or safari when mouse is over the link.He found the technique which only worked for IE but not for other browser but I&#8217;ve come up with a technique which works for all browser. This kind of technique is quite useful if you want to hide the actual link in status bar of browsers and show the different URL instead of actual one.</p>
<p><span id="more-210"></span></p>
<h4>Old technique to display hide actual URL  in the status bar</h4>
<p style="text-align: justify;">If you search in google with the keyword <a href="http://www.google.com/search?q=change+status+bar+text&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" target="_blank">change status bar text </a>, you&#8217;ll find that many codes in different websites which are using <strong>window.status</strong> to change the text of the status bar while mouse is over the link. For example,</p>
<pre class="prettyprint" style="overflow:auto">&lt;a href="http://www.sell.com/?referrer=225" onMouseOver="window.status='http://www.sell.com';
return true" onMouseOut="window.status=''"&gt;Click here &lt;/a&gt;</pre>
<p style="text-align: justify;">The above link displays &#8220;http://www.sell.com&#8221; instead of &#8220;http://www.sell.com/?referrer=225&#8243; in the status bar when mouse is mover the hyperlink. But, the main drawback of above code is that it only works in Internet Explorer(IE) . It doesn&#8217;t change the status bar text of the link in any other browsers like &#8220;Firefox&#8221;, &#8220;Safari&#8221; etc.</p>
<h4>How to display diferent URL of links in status bar of Firefox , Safari etc ?</h4>
<p style="text-align: justify;">To change the satus bar text of the the link in firefox and safari you&#8217;ve to just use a small technique with the help of &#8220;<strong>href</strong>&#8221; and &#8220;<strong>Onclick</strong>&#8221; attribute of the hyperlink. Let&#8217;s look at the this technique step by step,</p>
<ol>
<li>First, make a javaScript function and define it exactly as below,
<pre class="prettyprint" style="overflow:auto">    &lt;script language="javascript" type="text/javascript"&gt;
     function redirect(URL)
     {
       document.location=URL;
       return false;
     }
    &lt;/script&gt;</pre>
</li>
<li>Now, define the hyperlink with the status bar text in <strong>href</strong> attribute and call the above function from <strong>onClick</strong> attribute of the link like below,
<pre class="prettyprint" style="overflow:auto">&lt;a href="http://www.sell.com" onclick="return
redirect('http://www.sell.com/?referrer=225');"&gt;Click here&lt;/a&gt;</pre>
</li>
</ol>
<p style="text-align: justify;">As we know the we see the text in status bar which is defined in the href attribute of the hyperlink. And when you click the link, code within <strong>onclick</strong> event of element is called. We&#8217;ve taken the benefit of this phenomenon to show the different text .</p>
<p style="text-align: justify;">But remember, this technique also have a drawback as it doesn&#8217;t work if JavaScript is diabled in the web browsers. In that case, the browers will be redirecteed to URL in the <strong>href</strong> attribute. If you worried about disabled JavaScript then you can check this post to knnow how to <a href="http://roshanbh.com.np/2008/04/how-to-know-handle-disabled-javascript.html">handle disabled JavaScript in browser</a>.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=210&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/different-status-bar-text-hyperlink-mouseover.html/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>State preserved bottom hanging message box using jQuery</title>
		<link>http://roshanbh.com.np/2008/07/state-preserved-bottom-hanging-message-box-using-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/07/state-preserved-bottom-hanging-message-box-using-jquery.html#comments</comments>
		<pubDate>Wed, 23 Jul 2008 11:45:53 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=169</guid>
		<description><![CDATA[Last time, I&#8217;ve made the top floating message box using jquery. And a lot of people has asked me how can I preserve the state of that message box so that when it is closed.It won&#8217;t be open to for some time interval. Today, I&#8217;ve come with state preserved bottom hanging message box. When you [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fstate-preserved-bottom-hanging-message-box-using-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fstate-preserved-bottom-hanging-message-box-using-jquery.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Last time, I&#8217;ve made the top floating message box using jquery. And a lot of people has asked me how can I preserve the state of that message box so that when it is closed.It won&#8217;t be open to for some time interval. Today, I&#8217;ve come with state preserved bottom hanging message box. When you close the message box, it&#8217;s state is preserved in cookie created using JavScript so that this message box won&#8217;t show up for certain hours.</p>
<p><span id="more-169"></span></p>
<p style="text-align: justify;"><a href="http://roshanbh.com.np/examples/bottom-hanging-jquery" target="_blank"><strong>View Live Demo </strong></a></p>
<p style="text-align: justify;">I&#8217;m not going to post the HTML code, it is same the previous post of <a href="http://roshanbh.com.np/2008/07/top-floating-message-box-using-jquery.html">floating message box using jQuery</a>. You can refer to that article for HTML code.</p>
<h4>CSS code for state preserved hanging message</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">#message_box { </span>
<span style="color: #333399;">position: absolute;
left: 0px;
z-index: 10;
background:#ffc;
padding:5px;
border:1px solid #CCCCCC;
text-align:center;
width:99%;
display:none;
color:#0000FF;
font: bold 12px Verdana, Arial, Helvetica, sans-serif;</span>
<span style="color: #ff00ff;">}</span></pre>
<p style="text-align: justify;">The element with id &#8220;message_box&#8221; is made hidden first with it&#8217;s position set to &#8220;absolute&#8221; for making it hanging. Other attribute you can change according to your need.</p>
<h4>JavaScript Code for state preserved hanging message box</h4>
<p style="text-align: justify;">As this time, I&#8217;ve come up with the state preserved solution. I&#8217;ve used JavaScript for setting and getting value from cookie. I&#8217;ve used two functions getCookie()  directly taken from <a href="http://www.w3schools.com/JS/js_cookies.asp" target="_blank">w2school&#8217;s JavaScript cookie tutorial</a>.But I&#8217;ve modified the setCookie() functions where you can set the cookie expirty time in number of hours Here is that function,</p>
<pre class="prettyprint" style="overflow:auto">//function to set the cookie name, values and expiry time in hours
function setCookie(c_name,value,expireHours)
{
  var exhour=new Date(); //create the current date object
  exhour.setHours(exhour.getHours()+1); //setting hours
  document.cookie=c_name+ "=" +escape(value)+
  ((expireHours==null) ? "" : ";expires="+exhour.toGMTString());
}</pre>
<p style="text-align: justify;">Now, let&#8217;s dig through the jQuery code to provide the state preserved bottom hanging message box.</p>
<pre class="prettyprint" style="overflow:auto">//when the close button at right corner of the message box is clicked
$('#close_message').click(function()
{
  //the messagebox gets scrool down with top property and gets hidden with zero opacity
  $('#message_box').animate({ top:"-=15px",opacity:0 }, "slow");
   setCookie('show_message','no',1); //cookies is set to "no" value
});</pre>
<p style="text-align: justify;">As you can see above, when the cross icon is clicked the message box gets hidden and furtheremroe, it sets a cookie &#8220;show_message&#8221; with value &#8220;no&#8221; which expires in one hour. Now, look at the jquery code,</p>
<pre class="prettyprint" style="overflow:auto">if(getCookie('show_message')!='no')
{
  var pos=parseInt($(window).scrollTop())+parseInt($(window).height());
  $('#message_box').css("top",pos-26+"px");
  $('#message_box').show(); //display the message box

  //scroll the message box to the top offset of browser's scrool bar
  $(window).scroll(function()
  {
    var pos=parseInt($(window).scrollTop())+parseInt($(window).height());
    $('#message_box').animate({top:pos-26+"px" },{queue: false, duration: 500});
  });
}</pre>
<p style="text-align: justify;">As, you can see there is condition to show the message box and  code inside scroll event to execute. If the cookie is not set then the message box gets displayed and it will be shown to the bottom of the page according to the requirement.</p>
<p style="text-align: justify;"><a href="http://roshanbh.com.np/codes/bottom-hanging-jquery.zip" target="_blank"><strong>Download Full Source Code </strong></a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=169&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/state-preserved-bottom-hanging-message-box-using-jquery.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/45 queries in 1.821 seconds using disk: basic
Object Caching 2204/2301 objects using disk: basic

Served from: roshanbh.com.np @ 2012-02-08 20:12:06 -->
