<?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; tutorial</title>
	<atom:link href="http://roshanbh.com.np/category/tutorial/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>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>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>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>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 display pop-up message on mouse clicked position using jQuery</title>
		<link>http://roshanbh.com.np/2008/08/pop-up-message-mouse-clicked-position-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/08/pop-up-message-mouse-clicked-position-jquery.html#comments</comments>
		<pubDate>Mon, 04 Aug 2008 16:39:20 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[message box]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=203</guid>
		<description><![CDATA[Yesterday, my friend Sujit asked me how can we get the mouse clicked position and display the pop-up message in that mouse clicked position using jQuery.Today, I&#8217;ve come up with the tutorial for the solution of this problem. In this tutorial, you&#8217;ll see how to display the pop-up message in mouse clicked position using jQuery. [...]]]></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%2Fpop-up-message-mouse-clicked-position-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fpop-up-message-mouse-clicked-position-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;">Yesterday, my friend <a href="http://sks.com.np" target="_blank">Sujit</a> asked me how can we get the mouse clicked position and display the pop-up message in that mouse clicked position using jQuery.Today, I&#8217;ve come up with the tutorial for the solution of this problem. In this tutorial, you&#8217;ll see how to display the pop-up message in mouse clicked position using jQuery. When you click the mouse in any position of document, the pop-up message gets displayed with the mouse position around the middle part of the pop-up message.</p>
<p><span id="more-203"></span></p>
<p style="text-align: justify;"><a href="http://roshanbh.com.np/examples/popup-message/" target="_blank"><strong>Live Demo</strong></a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://roshanbh.com.np/codes/popup-message.zip"><strong>Download Full Source Code</strong></a></p>
<h4>HTML code to display pop-up message on mouse clicked position</h4>
<pre class="prettyprint" style="overflow:auto ">&lt;div id="popuup_div" class="popup_msg"&gt;
   ....you can write the mssage here...
&lt;/div&gt;</pre>
<p style="text-align: justify;">As you can above, the element displaying pop-up message is defined with the id &#8220;<span style="color: #000080;">popup_div</span>&#8221; and class of this element is &#8220;<span style="color: #000080;">popup_msg</span>&#8220;. You can write your custom message inside that div.</p>
<h4>CSS code to display pop-up message on mouse clicked position</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">.popup_msg{</span>
<span style="color: #333399;">position:absolute;
z-index:10;
width:172px;
height:102px;
text-align:center;
color:#FF0000;
font: 14px Verdana, Arial, Helvetica, sans-serif;
background:url(bg_image.gif) bottom right no-repeat;
display:none;</span>
<span style="color: #ff00ff;">}</span></pre>
<p style="text-align: justify;">The above CSS attribute is straightforward and you can change the attribute according to your requirement. But remember that, the <span style="color: #000080;">position</span> attribute should be set to <span style="color: #000080;">absolute</span> value and <span style="color: #000080;">z-index</span> should be greater than the other element&#8217;s z-index. Furthermore, the width and height attribute must be set according to the background image of pop-up message.</p>
<h4>JavaScript ( jQuery ) code for displaying pop-up message</h4>
<pre class="prettyprint" style="overflow:auto ">$(document).click(function(e)
{
  //getting height and width of the message box
  var height = $('#popuup_div').height();
  var width = $('#popuup_div').width();
  //calculating offset for displaying popup message
  leftVal=e.pageX-(width/2)+"px";
  topVal=e.pageY-(height/2)+"px";
  //show the popup message and hide with fading effect
  $('#popuup_div').css({left:leftVal,top:topVal}).show().fadeOut(1500);
});</pre>
<p style="text-align: justify;">As the above code is well document. I&#8217;m just going to give you the brief description. First of all, we took the height and width of the pop-up element. After that, we&#8217;ve calculated the <span style="color: #000080;">left</span> and <span style="color: #000080;">top</span> offset of element so that it gets displayed with the mouse position is around in it&#8217;s middle part. of the element With the last  line of jQuery code, pop-up message&#8217;s left and top position is set and displayed. This pop-up message gets hidden with fading effect with the <span style="color: #000080;">fadeOut()</span> function of jQuery.</p>
<p style="text-align: justify;"><a href="http://roshanbh.com.np/examples/popup-message/" target="_blank"><strong>Live Demo</strong></a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://roshanbh.com.np/codes/popup-message.zip"><strong>Download Full Source Code</strong></a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=203&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/pop-up-message-mouse-clicked-position-jquery.html/feed</wfw:commentRss>
		<slash:comments>25</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>
		<item>
		<title>Top Floating message box using jQuery</title>
		<link>http://roshanbh.com.np/2008/07/top-floating-message-box-using-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/07/top-floating-message-box-using-jquery.html#comments</comments>
		<pubDate>Sun, 13 Jul 2008 09:29: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[message box]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=162</guid>
		<description><![CDATA[Last time, I&#8217;ve shown you how to create a alert box using jQuery. This time, I&#8217;ve come up with another tutorial to show you how to display floating message box in the top of  the browser using jQuery. The message box always get displayed at the top of the browser although you move across 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%2F07%2Ftop-floating-message-box-using-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Ftop-floating-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 shown you how to create a alert box using jQuery. This time, I&#8217;ve come up with another tutorial to show you how to display floating message box in the top of  the browser using jQuery. The message box always get displayed at the top of the browser although you move across the document with help of scroll bar. Now, let&#8217;s kick out this tutorial for creating floating message box using jQuery.</p>
<p><span id="more-162"></span></p>
<p style="text-align: justify; font-weight: bold;"><a href="http://roshanbh.com.np/examples/floating-message-jquery/" target="_blank">LIVE DEMO</a></p>
<h4>HTML code for floating message box using jQuery</h4>
<pre class="prettyprint" style="overflow:auto">&lt;div id="message_box"&gt;
    &lt;img id="close_message" style="float:right;cursor:pointer" src="12-em-cross.png" /&gt;
    The floating message goes here
&lt;/div&gt;

&lt;div&gt;
  ..............
  other content goes here
  ..................
&lt;/div&gt;
</pre>
<p style="text-align: justify;">The message box which is going to float in the top of the browser is inside the div with id &#8220;message-box&#8221; and this div is defined with the class &#8220;cornerbox&#8221;. And the small image with id &#8220;close_message&#8221; to close the message box and is displayed in the right hand side by setting the <span style="color: #333399;">float</span> attribute of CSS to <span style="color: #333399;">right</span> .</p>
<h4>CSS code for floating message box using jQuery</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">#message_box {</span>
<span style="color: #333399;">position: absolute;
top: 0; left: 0;
z-index: 10;
background:#ffc;
padding:5px;
border:1px solid #CCCCCC;
text-align:center;
font-weight:bold;
width:99%;</span>
<span style="color: #ff00ff;">}</span></pre>
<p style="text-align: justify;">You can see that CSS code for the floating message box is straightforward and you can change the color , size etc. according to your choice. But keep in mind that, &#8220;position&#8221; property must be absolute so that this message box doesn&#8217;t distract the other boxes and &#8220;z-index&#8221; must be set higher so that the it overlaps the other content of the web page.</p>
<h4>jQuery code for floating message box</h4>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript" language="javascript" src="jquery-1.2.6.min.js"&gt;&lt;/script&gt;</pre>
<p style="text-align: justify;">You must notice that I&#8217;ve used jquery 1.2.6 in this example as dimension plugin of jquery is embedded in the this version of jQuery. If you use the lesser version of jQuery than 1.2.6 then must use the dimension plugin of jQuery to use this example.</p>
<pre class="prettyprint" style="overflow:auto">//scroll the message box to the top offset of browser's scrool bar
$(window).scroll(function()
{
  $('#message_box').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 350});
});
</pre>
<p style="text-align: justify;">As you can when the window gets scrolled this function is called and the box gets moved as the &#8220;top&#8221; property of message box is set to different pixel using <a href="http://docs.jquery.com/Plugins/dimensions/scrollTop">scrollTop()</a> function, which had been the part dimension plugin of jQuery. This function return the scroll top offset of the matched element and in our example this return the scroll top offeset of the browser&#8217;s window. Another thing you must notice in the animate function that queue is set to false which makes the animation to skip the queue and begins running immediately otherwise the animation may stuck in the queue and looks ugly.</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");
});</pre>
<p style="text-align: justify;">It is the simple animation when the image with close sign is clicked, the message box slides down below and gets hidden because its opacity set to zero in the animation function.</p>
<p style="text-align: justify; font-weight: bold;"><a href="http://roshanbh.com.np/codes/floating-message-jquery.zip" target="_blank">DOWNLOAD FULL SOURCE CODE </a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=162&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/top-floating-message-box-using-jquery.html/feed</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Flashing Alert Message Box using JQuery</title>
		<link>http://roshanbh.com.np/2008/07/animated-alert-message-box-using-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/07/animated-alert-message-box-using-jquery.html#comments</comments>
		<pubDate>Wed, 02 Jul 2008 17:11:49 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[alertbox]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[messegeabox]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=126</guid>
		<description><![CDATA[As you can see in the poll running on this blog, jQuery is leading among the other JavaScript framework by a good margin. And, this blogger is also a great fan of jQuery.This time, I&#8217;ve come up with another tutorial of jquery. In this post I&#8217;ll show you how to make sliding and flashing alert [...]]]></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%2Fanimated-alert-message-box-using-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fanimated-alert-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;">As you can see in the poll running on this blog, jQuery is leading among the other JavaScript framework by a good margin. And, this blogger is also a great fan of jQuery.This time, I&#8217;ve come up with another tutorial of jquery. In this post I&#8217;ll show you how to make sliding and flashing alert box in top left corner of the browser using jQuery. This alert box gets displayed with animation when the page is loaded for the first time.</p>
<p><span id="more-126"></span></p>
<p><a href="http://roshanbh.com.np/examples/alert-box/" target="_blank"><strong>Live Demo</strong></a></p>
<p style="text-align: justify;">Let&#8217;s start looking at the HTML, CSS and JavaScript Code in jquery to make the animated alerting message box using jQuery.</p>
<h4>HTML code for Flashing Alert Message using jQuery</h4>
<pre class="prettyprint" style="overflow:auto ">&lt;div id="object" class="message"&gt;
  &lt;img id="close_message" style="float:right;cursor:pointer" src="12-em-cross.png" /&gt;
  &lt;strong&gt;Massive Offer &lt;/strong&gt;
  &lt;p&gt;The detail of this offer goes here dude just Grab this offer !!!!!!! &lt;/p&gt;
&lt;/div&gt;</pre>
<p style="text-align: justify;">As you the message box which I want to display is inside the &#8220;div&#8221; element with id &#8220;object&#8221;. And there is an image inside of this box with id &#8220;close_window&#8221;, when this image is clicked the message box gets vanished with fading effect.</p>
<h4>CSS code for Flashing Alert Message Box using jQuery</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">.message{</span>
<span style="color: #333399;">border:1px solid #CCCCCC;
position:absolute;
width:150px;
border:1px solid #c93;
background:#ffc;
padding:5px;
left:0px;
top : -170px;</span>
<span style="color: #ff00ff;">}</span></pre>
<p>As you know, I&#8217;m very poor in selecting good colors, please forgive me for the bad design of the alert box.</p>
<p style="text-align: justify;">Above is the class which I&#8217;ve used for flashing message box. The position property must be &#8220;absolute&#8221; and the top property should be choosen such a way that the message box gets hidden in the top part of the browser. The other part property of CSS is straightforward you can change them according to your need.</p>
<h4>JavaScript code in jQuery for Flashing Alert Message Box</h4>
<pre class="prettyprint" style="overflow:auto ">$(document).ready(function()
{
  //first slide down and blink the message box
  $("#object").animate({
  top: "0px"
  }, 2000 ).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);

  //close the message box when cross red image is clicked
  $("#close_message").click(function()
  {
     $("#object").fadeOut("slow");
  });
});</pre>
<p style="text-align: justify;">As you know, we&#8217;ve placed the message box in the top of the browser in such a way that it is not visible in the browsers. Now, the above jQuery code is used this message box to get slide down and gets flashed in the browser. For this, I&#8217;ve used animate() and fadeOut() and fadeIn() functions of jQuery.</p>
<p>And, when the close image of the message box is clicked, the alert box gets vanished with the fading effect.</p>
<p><a href="http://roshanbh.com.np/codes/alert-box.zip" target="_blank"><strong>Download Full Source Code </strong></a></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=126&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/animated-alert-message-box-using-jquery.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Block Shuffling effect using jquery</title>
		<link>http://roshanbh.com.np/2008/06/block-shuffle-effect-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/06/block-shuffle-effect-jquery.html#comments</comments>
		<pubDate>Sun, 08 Jun 2008 05:14:54 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<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=122</guid>
		<description><![CDATA[Last time, I showed you how to navigate the content in various effect using jQuery. In this post, I&#8217;ll show you how can you generate the shuffle effect i.e one block moves under another block with sliding from the left. LIVE DEMO Now let&#8217;s look at the various code to perform this task. HTML and [...]]]></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%2F06%2Fblock-shuffle-effect-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F06%2Fblock-shuffle-effect-jquery.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Last time, I showed you how to <a href="http://roshanbh.com.np/2008/05/animated-content-navigation-jquery.html ">navigate the content in various effect</a> using jQuery. In this post, I&#8217;ll show you how can you generate the shuffle effect i.e one block moves under another block with sliding from the left.</p>
<p><span id="more-122"></span></p>
<p style="text-align: justify;"><strong><a href="http://roshanbh.com.np/examples/block-shuffle" target="_blank">LIVE DEMO</a></strong></p>
<p style="text-align: justify;">Now let&#8217;s look at the various code to perform this task.</p>
<h4>HTML and CSS code for shuffling the block</h4>
<p style="text-align: justify;">This code is same as the the one I&#8217;ve shown you in the <a href="http://roshanbh.com.np/2008/05/animated-content-navigation-jquery.html" target="_blank">content navigation effect using jquery</a> post. <a href="http://roshanbh.com.np/2008/05/animated-content-navigation-jquery.html" target="_blank">Please refer to that post</a> to view the HTML and CSS code for detail. Note that, each link&#8217;s &#8220;href&#8221; attribute is pointing to the &#8220;id&#8221; element of the block.</p>
<h4>JavaScript code in jQuery to shuffle the block</h4>
<pre class="prettyprint" style="overflow:auto">//when the anchor is clicked
$("a.linkclass").click(function()
{
   //check weather the visible block and clicked link's block is same or different
   if($(this).attr("href")!="#"+$(".msg_body:visible").attr("id"))
   {
      //reduces the z-index and margin of left side increased and decreased by 400px and hide
      $(".msg_body:visible").css("z-index","0").animate({marginLeft: "-=400px"},"500").animate({marginLeft: "+=400px"},"500").hide("1");
     //increase the z-index of the new visible block
     $($(this).attr("href")).css("z-index","10").fadeIn(400);
   }
}</pre>
<p style="text-align: justify;">When the anchor with the &#8220;linkclass&#8221; is clicked, first of all it is check that weather the clicked anchor&#8217;s link is same as the visible block. If it is the same then the animation doesn&#8217;t take place. When these are different, then the visible block&#8217;s &#8220;z-index&#8221; is decreased to zero and it gets slides to the left and then into right by using altering the value in the &#8220;margin-left&#8221; property. And, finally this block gets hidden. In the meanwhile, block whose name in the &#8220;href&#8221; attribute of the clicked anchor gets visible with fade in effect and &#8220;z-index&#8221; of this block is set to &#8220;10&#8243; so that it overlaps the slided block.</p>
<p style="text-align: justify;"><strong><a href="http://roshanbh.com.np/codes/block-shuffle.zip" target="_blank">Download Full Source Code</a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=122&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/06/block-shuffle-effect-jquery.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Making accordion menu using jquery</title>
		<link>http://roshanbh.com.np/2008/06/accordion-menu-using-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/06/accordion-menu-using-jquery.html#comments</comments>
		<pubDate>Sun, 01 Jun 2008 09:57:55 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=115</guid>
		<description><![CDATA[Last time, I&#8217;ve shown how to create accordion using jquery. But, In this post I&#8217;ll show you how can you create fancy accordion menu using jQuery. In this post, you&#8217;ll see two examples of accordion. First menu&#8217;s visibility get&#8217;s toggled on clicking on the header while the another menu&#8217;s visibility get&#8217;s toogled when mouse is [...]]]></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%2F06%2Faccordion-menu-using-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F06%2Faccordion-menu-using-jquery.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Last time, I&#8217;ve shown how to create <a href="http://roshanbh.com.np/2008/03/make-accordion-using-jquery.html">accordion using jquery</a>. But, In this post I&#8217;ll show you how can you create fancy accordion menu using jQuery. In this post, you&#8217;ll see two examples of accordion. First menu&#8217;s visibility get&#8217;s toggled on clicking on the header while the another menu&#8217;s visibility get&#8217;s toogled when mouse is moved over it.</p>
<p><span id="more-115"></span></p>
<h4>Live Demo of accordion menu using jQuery</h4>
<p><iframe src="http://roshanbh.com.np/examples/accordion-menu" width="459" height="200" scrolling="no" frameborder="0"></iframe></p>
<h4>HTML structure for  accordion menu using jQuery</h4>
<pre class="prettyprint" style="overflow:auto">&lt;div id="firstpane" class="menu_list"&gt;
  &lt;p class="menu_head"&gt;Header-1&lt;/p&gt;
    &lt;div class="menu_body"&gt;
	&lt;a href="#"&gt;Link-1&lt;/a&gt;
    &lt;/div&gt;
  &lt;p class="menu_head"&gt;Header-2&lt;/p&gt;
    &lt;div class="menu_body"&gt;
	&lt;a href="#"&gt;Link-1&lt;/a&gt;
    &lt;/div&gt;
  &lt;p class="menu_head"&gt;Header-3&lt;/p&gt;
    &lt;div class="menu_body"&gt;
        &lt;a href="#"&gt;Link-1&lt;/a&gt;
   &lt;/div&gt;
&lt;/div&gt;</pre>
<p align="justify">As you can see the structure, the elements of the menu are inside the div with class &#8220;menu_list&#8221;. And each blocks of menu contains the header with class &#8220;menu_head&#8221; and div with class &#8220;menu_body&#8221;. Note that, there is another pane with the id &#8220;secondpane&#8221; whose code is similar as above and not posted above.</p>
<h4>CSS code  for accordion menu using jQuery</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">.menu_list {</span>
	<span style="color: #000080;">width: 150px;</span>
<span style="color: #ff00ff;">}
.menu_head {</span>
	<span style="color: #333399;">padding: 5px 10px;
	cursor: pointer;
	position: relative;
	margin:1px;
       font-weight:bold;
       background: #eef4d3 url(left.png) center right no-repeat;</span>
<span style="color: #ff00ff;">}
.menu_body {</span>
	<span style="color: #333399;">display:none;</span>
<span style="color: #ff00ff;">}
.menu_body a {</span>
 <span style="color: #333399;"> display:block;
  color:#006699;
  background-color:#EFEFEF;
  padding-left:10px;
  font-weight:bold;
  text-decoration:none;</span>
<span style="color: #ff00ff;">}
.menu_body a:hover {</span>
  <span style="color: #333399;">color: #000000;
  text-decoration:underline;</span>
<span style="color: #ff00ff;">}</span></pre>
<p align="justify">I&#8217;m not a good color chooser so please forgive me for the color combinations. Above CSS code is straight forward and you can change is according to your need. Note that, the display property in &#8220;menu_body&#8221; is set to &#8220;hidden&#8221; so that the menu links are hidden when the page is loaded. Furthermore, the display property in the link inside &#8220;menu_body&#8221; class is set to &#8220;block&#8221; so that each menu appears in new line. You can see a image in the &#8220;menu_head&#8221; class, this is the image which gets changes with the visibility of the menu item in each menu&#8217;s head.</p>
<p align="justify">I&#8217;ve used the images from <a href="http://sweetie.sublink.ca/">sweetie icon pack</a>, you can download the other <a rel="nofollow" href="http://sweetie.sublink.ca/">beautiful icon from the their website</a>.</p>
<h4>Javascript Code using jQuery</h4>
<p align="justify">Now finally look at the JavaScript code to accomplish this, first of we need to import the jQuery library</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript" language="javascript" src="jquery.js"&gt;&lt;/script&gt;</pre>
<p align="justify">And, then we need to write few lines of simple code in jQuery to do this, let&#8217;s look at the jquery code of the first accordion menu whose visibility gets toggled on the mouse click event on each header,</p>
<pre class="prettyprint" style="overflow:auto">//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
$("#firstpane p.menu_head").click(function()
{
    $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
    $(this).siblings().css({backgroundImage:"url(left.png)"});
});</pre>
<p align="justify">When the paragraph with class &#8220;menu_head&#8221; inside the element with the id &#8220;firstpane&#8221; gets clicked, the background image of it changed to down arrow. And then, next div with class &#8220;menu_body&#8221; gets slided in toggling it&#8217;s visibility. Furthermore, the other sibling&#8217;s div with class &#8220;menu_body&#8221; gets slided up. And then, the background image of the other sibling&#8217;s of &#8220;p&#8221; is changed to left arrow. Now look at the code of the accordion menu under mouse over effect.</p>
<pre class="prettyprint" style="overflow:auto">//slides the element with class "menu_body" when mouse is over the paragraph
$("#secondpane p.menu_head").mouseover(function()
{
   $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
   $(this).siblings().css({backgroundImage:"url(left.png)"});
});</pre>
<p align="justify">This code is preety similar to the above code but the difference is only that this accordion menu works on the mouse over effect whereas the above accordion menu works on the mouse click event.</p>
<p><strong><a href="http://roshanbh.com.np/codes/accordion-menu.zip" target="_blank">Download Source Code</a></strong></p>
<p>If you want to learn more about jQuery then you can check the following books and buy them.I really recommend the book &#8220;<strong>jQuery in Action</strong>&#8221; for starting your way for jQuery.</p>
<pre><a rel="nofollow" href="http://affiliate.buy.com/gateway.aspx?adid=17662&amp;aid=10387773&amp;pid=3141609&amp;sURL=http%3A%2F%2Fwww.buy.com%2Fprod%2Flearning-jquery-better-interaction-design-and-web-development-with%2Fq%2Floc%2F106%2F204995923.html&amp;cjsku=204995923" target="_top"><img src="http://ak.buy.com/db_assets/prod_images/923/204995923.jpg" border="0" alt="Learning Jquery: Better Interaction Design and Web Development with Simple JavaScript Techniques" /></a>
<img src="http://www.afcyhf.com/image-3141609-10387773" border="0" alt="" width="1" height="1" />

<a rel="nofollow" href="http://affiliate.buy.com/gateway.aspx?adid=17662&amp;aid=10387773&amp;pid=3141609&amp;sURL=http%3A%2F%2Fwww.buy.com%2Fprod%2Fjquery-in-action%2Fq%2Floc%2F106%2F205775038.html&amp;cjsku=205775038" target="_top"><img src="http://ak.buy.com/db_assets/prod_images/038/205775038.jpg" border="0" alt="Jquery in Action" /></a>
<img src="http://www.afcyhf.com/image-3141609-10387773" border="0" alt="" width="1" height="1" /></pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=115&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/06/accordion-menu-using-jquery.html/feed</wfw:commentRss>
		<slash:comments>202</slash:comments>
		</item>
		<item>
		<title>Default arguments in the functions of PHP</title>
		<link>http://roshanbh.com.np/2008/05/default-arguments-functions-php.html</link>
		<comments>http://roshanbh.com.np/2008/05/default-arguments-functions-php.html#comments</comments>
		<pubDate>Tue, 27 May 2008 08:57:52 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=113</guid>
		<description><![CDATA[If you are unaware of default argument in function then you should know that you candefine the function with default arguments in PHP as you can do it C and C++. Providing default arguments in the function can be very useful when you&#8217;ve to extend the the functionality of the previously written functions. &#160; Example [...]]]></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%2F05%2Fdefault-arguments-functions-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F05%2Fdefault-arguments-functions-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;">If you are unaware of default argument in function then you should know that you candefine the function with default arguments in PHP as you can do it C and C++. Providing default arguments in the function can be very useful when you&#8217;ve to extend the the functionality of the previously written functions.</p>
<p style="text-align: justify;"><span id="more-113"></span></p>
<p style="text-align: justify;">&nbsp;</p>
<h4>Example of using default argument in the function of PHP</h4>
<p align="justify">Let&#8217;s suppose that you&#8217;ve already written a function to &#8220;calculate the amount collected in day by site&#8221;</p>
<p><span style="color: #000080;">function getAmountCollected($day)<br />
{<br />
//code for function goes here<br />
}</span></p>
<p style="text-align: justify;">Assume that this function is called from around 20 places in your project. After sometime, your client asked you to find the  &#8221; amount collected by site in that date range&#8221;. For this case, you need to pass two parameters(start date and end date) to the function.</p>
<p style="text-align: justify;"><strong>Do you write another function or extend the functionality of the same function?</strong></p>
<p style="text-align: justify;">I would use the same function for this purpose to minimize the code. But one major problem, we&#8217;ve already called the functions from many places with the single argument. How can we define the same function which can be called both with single and double argument? In this case, default argument comes handy,</p>
<p><span style="color: #000080;">function getAmountCollected($day, $end_day=&#8217;none&#8217;)<br />
{<br />
//code for function goes here<br />
}</span></p>
<p style="text-align: justify;">As you can see above, we&#8217;ve placed the second argument in this function like &#8220;<span style="color: #000080;">$end_day=&#8217;none&#8217;</span>&#8220;, which is called the <strong>default argument</strong> of the function. You can call this function with both single and double arguments.</p>
<p style="text-align: justify;">And, when the second argument is not supplied while calling the function, the variable &#8220;$end_day&#8221; contains &#8220;none&#8221; value in it. i.e when we call this function called like this with single argument</p>
<p style="text-align: justify;"><span style="color: #000080;">getAmountCollected(&#8217;2008-05-14&#8242;); //remember single argument</span></p>
<p style="text-align: justify;">then the second parameter will have &#8220;none&#8221; value in it in the called function.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=113&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/05/default-arguments-functions-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>8 useful server variables available in PHP</title>
		<link>http://roshanbh.com.np/2008/05/useful-server-variables-php.html</link>
		<comments>http://roshanbh.com.np/2008/05/useful-server-variables-php.html#comments</comments>
		<pubDate>Tue, 13 May 2008 10:42:20 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=107</guid>
		<description><![CDATA[You guys must have know about server variables in PHP. Server Variables are those variables which are inside the super global array named $_SERVER available in PHP. There are many server variables in PHP and some of them are very useful for fore developing PHP projects. I&#8217;m going to post here some of the very [...]]]></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%2F05%2Fuseful-server-variables-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F05%2Fuseful-server-variables-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">You guys must have know about server variables in PHP. Server Variables are those variables which are inside the super global array named $_SERVER available in PHP. There are many server variables in PHP and some of them are very useful for fore developing PHP projects. I&#8217;m going to post here some of the very useful server variables available in PHP development.</p>
<p><span id="more-107"></span></p>
<h4>8 Useful server variables available in PHP</h4>
<p align="justify"><strong><span style="color: #333399;">1) $_SERVER['REQUEST_URI'] </span></strong>- It return the URL in to access the page which is executing the script. If you need to type http://www.example.com/product.php?id=5 to access the page then $_SERVER['REQUEST_URI'] returns &#8220;/product.php?id=5&#8243;.</p>
<p align="justify"><strong><span style="color: #000080;">2) $_SERVER['DOCUMENT_ROOT']</span></strong> &#8211; Returns the root directory of the server which is specified in the configuration file of server. This variable usually returns the path like &#8220;/usr/yoursite/www&#8221; in Linux and &#8220;D:/xamps/xampp/htdocs&#8221; in windows.</p>
<p align="justify"><span style="color: #000080;"><strong>3) $_SERVER['HTTP_HOST']</strong></span> &#8211; Returns the host&#8217;s name as found in the http header. This variable usually returns the path like &#8220;example.com&#8221; when the you find &#8220;http://example.com&#8221; in browser&#8217;s address-bar and return &#8220;www.example.com&#8221; when you see http://www.example.com in the address-bar. This is quite useful when you&#8217;ve to preserve session while making online payment using PHP since session stored for &#8220;http://example.com&#8221; is not same as for the &#8220;http://www.example.com&#8221;.</p>
<p align="justify"><strong><span style="color: #000080;">4) $_SERVER['HTTP_USER_AGENT'] </span></strong>- Returns the user agent&#8217;s (browser) detail accessing the web page. We can use <span style="color: #333399;">strpos($_SERVER["HTTP_USER_AGENT"],&#8221;MSIE&#8221;)</span> to detect Microsoft Internet explorer or you can use <span style="color: #000080;">strpos($_SERVER["HTTP_USER_AGENT"],&#8221;Firefox&#8221;)</span> to detect firefox browser in PHP.</p>
<p align="justify"><span style="color: #000080;"><strong>5) $_SERVER['PHP_SELF'] </strong></span>- Returns the file-name of the currently executing script. Let&#8217;s suppose that you&#8217;re accessing the URL  http://www.example.com/product.php?id=5 then $_SERVER['PHP_SELF'] returns &#8220;/product.php&#8221; in your script.</p>
<p align="justify"><strong><span style="color: #000080;">6) $_SERVER['QUERY_STRING']</span></strong> &#8211; Returns the query string if query string is used to access the script currently executing. Query strings are those string which is available after &#8220;?&#8221; sign.if you use $_SERVER['QUERY_STRING'] in the script executing the following URL &#8220;http://www.example.com/index.php?id=5&amp;page=product&#8221; then it returns &#8220;id=5&amp;page=product&#8221; in your script.</p>
<p align="justify"><span style="color: #000080;"><strong>7) $_SERVER['REMOTE_ADDR']</strong></span> &#8211; Returns the IP address of remote machine accessing the current page. But you can&#8217;t relie on $_SERVER['REMOTE_ADDR'] to get the real IP address of client&#8217;s machine. See this article to know how to get <a href="http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html">real IP addrees in PHP</a>.</p>
<p align="justify"><span style="color: #000080;"><strong>8 ) $_SERVER['SCRIPT_FILENAME']</strong> </span>- Returns the absolute path of the file which is currently executing. It returns path like &#8220;var/example.com/www/product.php&#8221; in Linux and path like &#8220;D:/xampp/xampp/htdocs/test/example.php&#8221; in windows.</p>
<p align="justify">
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=107&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/05/useful-server-variables-php.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Date format validation in PHP</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html</link>
		<comments>http://roshanbh.com.np/2008/05/date-format-validation-php.html#comments</comments>
		<pubDate>Sun, 11 May 2008 11:20:19 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=105</guid>
		<description><![CDATA[Today Sushil asked me how can we validate the date which is entered from textbox in &#8220;YYYY-MM-DD&#8221; format. Well, we can validate the format of the date using regular expression but how to validate weather that date is valid date or not, such as &#8220;2007-02-29&#8243; is the correct format of the date but it&#8217;s not [...]]]></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%2F05%2Fdate-format-validation-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F05%2Fdate-format-validation-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 Sushil asked me how can we validate the date which is entered from textbox in &#8220;YYYY-MM-DD&#8221; format. Well, we can validate the format of the date using regular expression but how to validate weather that date is valid date or not, such as &#8220;2007-02-29&#8243; is the correct format of the date but it&#8217;s not the valid date.</p>
<p><span id="more-105"></span></p>
<p style="text-align: justify;">To overcome that situation, I&#8217;ve used <a href="http://www.php.net/checkdate" target="_blank">checkdate()</a> function available in PHP for validation of date.</p>
<h4>Function to validate date format in PHP</h4>
<pre class="prettyprint" style="overflow:auto">function checkDateFormat($date)
{
  //match the format of the date
  if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/&quot;, $date, $parts))
  {
    //check weather the date is valid of not
	if(checkdate($parts[2],$parts[3],$parts[1]))
	  return true;
	else
	 return false;
  }
  else
    return false;
}</pre>
<p style="text-align: justify;">In the above function, first of all format of date is validated using regular expression. As you can see the in the preg_match() function, there are three expression each separated by &#8220;-&#8221; and  there can be only digits of length of 4,2 and 2 in these expressions. If the date format is incorrect then this function returns &#8220;false&#8221; value. And, if the supplied string contains the valid date format then the part matching each expression are stored in the &#8220;$parts&#8221; array. Such as, if we supply &#8220;2007-03-12&#8243; then &#8220;2007&#8243;, &#8220;03&#8243; and &#8220;12&#8243; are stored in the &#8220;$parts&#8221; array. After that, <a href="http://www.php.net/checkdate" target="_blank">checkdate()</a> function of PHP is used check weather the supplied date is valid date or not.</p>
<h4>Example</h4>
<pre class="prettyprint" style="overflow:auto">echo checkDateFormat("2008-02-29"); //return true
echo checkDateFormat("2007-02-29"); //return false</pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=105&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/05/date-format-validation-php.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Animated content navigation effect using jquery</title>
		<link>http://roshanbh.com.np/2008/05/animated-content-navigation-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/05/animated-content-navigation-jquery.html#comments</comments>
		<pubDate>Thu, 08 May 2008 06:58:20 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=104</guid>
		<description><![CDATA[I always get bored with the same stuffs. And, I see same kind of content navigation to the different websites. Click a link, let&#8217;s the whole web page gets loaded and new page gets displayed. It would be better to show another content in the same page with few animation without loading the whole page. [...]]]></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%2F05%2Fanimated-content-navigation-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F05%2Fanimated-content-navigation-jquery.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">I always get bored with the same stuffs. And, I see same kind of content navigation to the different websites. Click a link, let&#8217;s the whole web page gets loaded and new page gets displayed. It would be better to show another content in the same page with few animation without loading the whole page.</p>
<p><span id="more-104"></span></p>
<p align="justify">In this post, I&#8217;ll show you how to make various animation to the content using jQuery. First of let&#8217;s start looking at the HTML and CSS code,</p>
<p align="justify"><strong>HTML Code for animated content navigation </strong></p>
<pre class="prettyprint" style="overflow:auto ">&lt;a href="#home" class="linkclass" &gt;Home&lt;/a&gt;
&lt;a href="#about_us" class="linkclass" &gt;About Us&lt;/a&gt;
&lt;a href="#service" class="linkclass" &gt;Services&lt;/a&gt;
&lt;a href="#contact_us" class="linkclass" &gt;Contact Us&lt;/a&gt;

&lt;div class="container"&gt;
    &lt;div id="home" class="msg_body"&gt; content goes here &lt;/div&gt;
    &lt;div id="about_us" class="msg_body"&gt; content goes here &lt;/div&gt;
    &lt;div id="service" class="msg_body"&gt; content goes here &lt;/div&gt;
    &lt;div id="contact_us" class="msg_body"&gt;  content goes here &lt;/div&gt;
&lt;/div&gt;</pre>
<p align="justify">As you can see above, the &#8220;href&#8221; attribute of the anchor tag is pointing to the id of the &#8220;div&#8221;. &#8220;Home&#8221; anchor tag is pointing to &#8220;#home&#8221;. In jquery, id of a element is represented by adding &#8220;#&#8221; prefix to the id of that element.</p>
<p align="justify"><strong>CSS code for animated content navigation</strong></p>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">.container
{</span>
  <span style="color: #333399;"> width:312px;
   margin-top:20px;</span>
<span style="color: #ff00ff;">}
.msg_body
{</span>
 <span style="color: #333399;"> border:1px solid #CCCCCC;
  padding: 5px;
  width: 300px;
  background-color:#F4F4F8;
  text-align:justify;
  position:absolute;</span>
<span style="color: #ff00ff;">}
.linkclass
{</span>
<span style="color: #333399;">  font-weight:bold;
  color:#006699;</span>
<span style="color: #ff00ff;">}</span></pre>
<p align="justify">Above CSS code is pretty straight forward and you can change it according to your need. Note that, there is position attribute to &#8220;absolute&#8221; in the &#8220;msg_body&#8221; class. Now let&#8217;s look at various the javaScript code in jQuery to make the various animated content navigation</p>
<p align="justify"><strong>Faded content navigation</strong></p>
<p align="justify"><strong><a href="http://roshanbh.com.np/examples/content-move/index.html" target="_blank">View Live Demo </a></strong></p>
<pre class="prettyprint" style="overflow:auto"> //hide the all div except first one
$('.msg_body:not(:first)').hide();
//when the anchor is clicked content gets faded
$("a.linkclass").click(function()
{
  $('.msg_body').fadeOut("slow");
  $($(this).attr("href")).fadeIn("slow");
});</pre>
<p align="justify">In the first line of javaScript code, all the element with class &#8220;msg_body&#8221; is made hidden except the first element with same class. And when the anchor with class &#8220;linkclass&#8221; is clicked, the element with class &#8220;msg_body&#8221; gets faded out which is being displayed in browser. And, the element with the id value in the &#8220;href&#8221; attribute of the clicked anchor tag, get displayed in browser with fading effect.</p>
<p align="justify"><strong>Shutter like content navigation effect<br />
</strong></p>
<p align="justify"><strong><a href="http://roshanbh.com.np/examples/content-move/index1.html" target="_blank">View Live Demo </a></strong></p>
<pre class="prettyprint" style="overflow:auto">//hide the all div except first one
$('.msg_body:not(:first)').hide();
//when the anchor is clicked content gets faded
$("a.linkclass").click(function()
{
   $('.msg_body').hide("fast");
   $($(this).attr("href")).show("slow");
});</pre>
<p align="justify">The code is same as the above code but here &#8220;hide()&#8221; and &#8220;show()&#8221; function of jQuery is used to hide and display the content in different manner.</p>
<p align="justify"><strong>Sliding Content Navigation Effect </strong></p>
<p align="justify"><strong><a href="http://roshanbh.com.np/examples/content-move/index3.html" target="_blank">View Live Demo </a></strong></p>
<pre class="prettyprint" style="overflow:auto"> //hide the all div except first one
 $('.msg_body:not(:first)').hide();
//when the anchor is clicked content gets faded
$("a.linkclass").click(function()
{
   $('.msg_body').slideUp("slow");
   $($(this).attr("href")).slideDown("slow"););
});</pre>
<p align="justify">This is another content navigation effect with sliding manner. &#8220;slideUp()&#8221; and &#8220;slideDown()&#8221; functions of jQuery is used to display this kind of effect.</p>
<p align="justify"><strong><a href="http://roshanbh.com.np/codes/content-move.zip">Download full source code</a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=104&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/05/animated-content-navigation-jquery.html/feed</wfw:commentRss>
		<slash:comments>26</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 1/70 queries in 2.428 seconds using disk: basic
Object Caching 2166/2332 objects using disk: basic

Served from: roshanbh.com.np @ 2012-02-08 20:45:07 -->
