<?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>Bagesh Singh&#039;s Blog &#187; jquery</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bageshsingh.com/bagesh-blog</link>
	<description>Shortest Distance to  Web Solutions &#38; Software Solutions</description>
	<lastBuildDate>Wed, 22 Feb 2012 18:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get and Set Form Element Values using jQuery</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/02/get-and-set-form-element-values-using-jquery/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/02/get-and-set-form-element-values-using-jquery/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 08:21:38 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1064</guid>
		<description><![CDATA[One of the most frequently asked questions about jQuery is to Get or Set values of HTML Form elements. The jQuery val() method lets you get and set values of form elements. Note: jQuery uses the val() method to both get and set values of form elements. If you pass a new value to the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most frequently asked questions about jQuery is to Get or Set values of HTML Form elements. The jQuery val() method lets you get and set values of form elements.</p>
<p><strong>Note:</strong> jQuery uses the val() method to both get and set values of form  elements. If you pass a new value to the val() method, it sets the value  for that element. If you do not pass a value to the val() method, it  returns the current value of that element. Let us see some examples:</p>
<p>Assuming you have a HTML page with the following form elements</p>
<pre>&lt;body&gt;
    TextBox &lt;br /&gt;
    &lt;input id="txtBox" type="text" /&gt;
    &lt;br /&gt;&lt;br /&gt;
    Radio Button &lt;br /&gt;
    &lt;input type="radio"  name="rad" value="RadioOne"/&gt; RadioOne
    &lt;input type="radio"  name="rad" value="RadioTwo"/&gt; RadioTwo
    &lt;br /&gt;&lt;br /&gt;
    Check Box &lt;br /&gt;
    &lt;input type=checkbox value="DotNetCurry"&gt;www.dotnetcurry.com&lt;br /&gt;
    &lt;input type=checkbox value="DevCurry"&gt;www.devcurry.com&lt;br /&gt;
    &lt;input type=checkbox value="SqlServerCurry"&gt;www.sqlservercurry.com
    &lt;br /&gt;&lt;br /&gt;
    Select Box &lt;br /&gt;
    &lt;select id="selectbox"&gt;
        &lt;option&gt;SelectOne&lt;/option&gt;
        &lt;option&gt;SelectTwo&lt;/option&gt;
        &lt;option&gt;SelectThree&lt;/option&gt;
    &lt;/select&gt;
    &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
    &lt;input id="btnSet" type="button" value="Set Values" /&gt;
    &lt;input id="btnGet" type="button" value="Get Values"
        disabled="disabled" /&gt;

    &lt;p id="para"&gt;&lt;/p&gt;
&lt;/body&gt;</pre>
<p>As  you can see, we have a page with a TextBox, RadioButton, CheckBox and a  Select/DropDown. We also have two buttons to Set and Get the values of  these form elements.</p>
<p><strong>Set Form Values using jQuery</strong></p>
<p>Use the following code to set form values using jQuery</p>
<pre>$("#btnSet").click(function () {
    $("#txtBox").val("Some text for TextBox");
    $("input:radio").val(["RadioTwo"]);
    $("input:checkbox").val(["DotNetCurry", "DevCurry"]);
    $("#selectbox").val("SelectTwo");
    $("#btnGet").removeAttr('disabled');
});</pre>
<p>The  code is self explanatory. We have used the val() method to set values  of the TextBox, RadioButton, CheckBox and Select respectively. Observe  that we have checked two out of three checkboxes.</p>
<p><strong>Get Form Values using jQuery</strong></p>
<p>Use the following code to get form values using jQuery</p>
<pre>$("#btnGet").click(function () {
    // first get the multiple selected checkbox items
    var chk = [];
    $("input:checkbox:checked").each(function() {
        chk.push($(this).val());
    });

    $("#para").html(
        $("#txtBox").val() + "&lt;br/&gt;" +
        $("input:radio[name=rad]:checked").val() + "&lt;br/&gt;" +
        chk.join(",") + "&lt;br/&gt;" +
        $("#selectbox").val()
        );
});</pre>
<p>As  you can see, we have used the val() method to get values from the  TextBox, RadioButton, CheckBox and Select/DropDown respectively. The  values are printed in a paragraph(para).</p>
<p><strong>Note:</strong> In case of the CheckBox, since there are multiple checked checkboxes,  we are looping through all checkboxes, pushing the value into an  array(chk) and then using the join method of the array, to have a  separated string of values.</p>
<p><strong>Stage 1:</strong> When the page loads</p>
<p><strong>Stage 2:</strong> When the ‘Set Values’ button is clicked</p>
<p><strong>Stage 3:</strong> When the ‘Get Values’ button is clicked</p>
<div id="seo_alrp_related"><h2>Posts Related to Get and Set Form Element Values using jQuery</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/sum-of-all-textbox-values-using-jquery/" rel="bookmark">Sum of all TextBox values using jQuery</a></h3><p>Here’s a simple script that sums up all textbox values using jQuery. Please note that I am not using any validation here to validate the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/textbox-to-accept-only-numbers-digits-using-jquery-2/" rel="bookmark">Textbox to accept only numbers (digits) using jquery</a></h3><p>Few days back, my friend Parleen asked me how can we make a textbox which just accepts only numbers specially digits only. And, for his ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/using-jquery-to-set-focus-on-the-first-textbox-kept-inside-a-paneldiv/" rel="bookmark">Using jQuery to Set Focus on the first TextBox Kept inside a Panel/Div</a></h3><p>In this post, we will use a small example to demonstrate how easy it is to use jQuery to select page elements and work on ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/using-jquery-to-trigger-a-link-only-if-a-condition-is-met/" rel="bookmark">Using jQuery to Trigger a Link only if a Condition is met</a></h3><p>I was recently asked a question. How to prevent a link from triggering if a condition is not met. Here’s a very simple code to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/find-nth-element-on-a-page-using-jquery/" rel="bookmark">Find Nth Element on a Page using jQuery</a></h3><p>A lot of developers often ask how to find the Nth element on a Page – for eg: Check if the user clicked inside the ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/02/get-and-set-form-element-values-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery UI 1.8.9 Released</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-ui-1-8-9-released/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-ui-1-8-9-released/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 08:20:28 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Product Releases]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1062</guid>
		<description><![CDATA[If you are using the jQuery UI library in your applications, then an important update is that the jQuery UI team has shipped a maintenance release &#8211; jQuery UI 1.8.9 The fixes are mainly for the Accordion, Datepicker and Tabs control and for the Draggable and Sortable interactions. The DatePicket widget now has support for [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using the jQuery UI library in your  applications, then an important update is that the jQuery UI team has  shipped a maintenance release &#8211;  jQuery UI 1.8.9</p>
<p>The   fixes are mainly for the Accordion, Datepicker and Tabs control and  for the Draggable and Sortable interactions. The DatePicket widget now  has support for the Algerian Arabic, Australian and New Zealand  localizations.</p>
<p>See the 1.8.9 Upgrade Guide for a list of changes that may affect you when upgrading from 1.8.8.  For full details on what’s included in this release see the 1.8.9 Changelog.</p>
<div id="seo_alrp_related"><h2>Posts Related to jQuery UI 1.8.9 Released</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-ui-1-8-with-new-plugins-and-plenty-of-bug-fixes-and-improvements/" rel="bookmark">jQuery UI 1.8 with new Plugins and plenty of Bug fixes and improvements</a></h3><p>jQuery UI 1.8 was released a couple of days ago (March 23rd 2010) with 5 new Plugins, one new effect and plenty of Bug fixes ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-mobile-alpha-and-jquery-1-4-3-released/" rel="bookmark">jQuery Mobile alpha and jQuery 1.4.3 released</a></h3><p>There were a couple of releases by the jQuery Team this week! The first alpha release of the jQuery Mobile project was announced a couple ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/jquery-interview-questions-%e2%80%93-third-part-of-jquery-interview-question/" rel="bookmark">JQuery Interview Questions – Third Part of Jquery Interview question</a></h3><p>Explain the concepts of “$ function” in jQuery with an example? The type of a function is “function”. There are a lot of anonymous functions ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/latest-jquery-and-jquery-ui-theme-links-on-google-cdn-2/" rel="bookmark">Latest jQuery and jQuery UI Theme links on Google CDN</a></h3><p>I have often seen developers asking where to find the jQuery UI Library and the jQuery UI Themes on Google CDN. Well here’s the list ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/latest-jquery-and-jquery-ui-theme-links-on-google-cdn/" rel="bookmark">Latest jQuery and jQuery UI Theme links on Google CDN</a></h3><p>I have often seen developers asking where to find the jQuery UI Library and the jQuery UI Themes on Google CDN. Well here’s the list ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-ui-1-8-9-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick &amp; Easy Way to Implement Drag n Share With jQuery</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/quick-easy-way-to-implement-drag-n-share-with-jquery/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/quick-easy-way-to-implement-drag-n-share-with-jquery/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 17:27:34 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=937</guid>
		<description><![CDATA[You must have seen the drag to share functionality on Mashable that lets visitors share the content on popular social networks intuitively. Just drag one of the images in an article and you’ll be able to share the article on your favorite social network by dropping the dragged image over its icon. Even, Nettuts has [...]]]></description>
			<content:encoded><![CDATA[<p>You must have seen the drag to share functionality on Mashable that lets visitors share the content on popular social networks intuitively. Just drag one of the images in an article and you’ll be able to share the article on your favorite social network by dropping the dragged image over its icon.<br />
Even, Nettuts has written a nice tutorial on how to implement this functionality into your website using jQuery. But here is a much elegant solution to achieve the drag n share effect using jQuery with just a line or two of JavaScript code.</p>
<p>Get the prettySociable Plugin<br />
To implement this functionality, you will need the prettySociable jQuery plugin written by Stéphane Caron. Download and extract the plugin, it contains everything you need to get up and running with drag n share.<br />
Include the Required Files<br />
To add drag n share to a page, add reference to jquery and prettySociable in your page’s headtag. The plugin folder also includes images and css folders in addition to js folder. You’ll need them too as css folder contains styles necessary for drag n share elements and images folder contains icons for various social networks.<br />
Here’s the complete code you need to add into the head tag.</p>
<p><script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <!--[if lte IE 6]> <mce:script mce_src="js/DD_belatedPNG.js" type="text/javascript" charset="utf-8"></mce:script><br />
 <![endif]--><br />
 <br />
 <script src="js/jquery.prettySociable.js" type="text/javascript"></script>Define Draggable Links  Now to add drag n share to your web page, add an anchor tag <a href="#"> with another attribute rel=&#8221;prettySociable&#8221;. Initialize prettySociable  After you have added the rel attribute, you need to initialize the script. Add this single line of code, just above the <script type="text/javascript">// <![CDATA[
    // Init prettySociable
    $.prettySociable();
// ]]&gt;</script><br />
Check out your page in browser and you should get drag to share functionality working nicely.<br />
Customizing the Default Settings<br />
Customizing the Shared Information</a></p>
<p><a href="#">When you add rel=&#8221;prettySociable&#8221; on an anchor tag with its href=&#8221;#&#8221;, this will share the URL of the current web page and use the title and meta description in head tag to display the tooltip on drag.<br />
But if you need to share a different URL instead of the current web page, specify a URL in thehref attribute. Also you can customize the tooltip information which is shown on dragging. You can specify custom title and description in the rel attribute in this way.rel=&#8221;prettySociable;title:custom title;excerpt:custom excerpt;&#8221;<br />
jQuery Recipes: A Problem-Solution Approach (Expert&#8217;s Voice in Web Development)<br />
Customizing the Sharing Panel</a></p>
<p><a href="#">By default prettySociable supports eight social networks but you can customize the social networks and their icons to your requirement. For that you’ll need to pass a settings object toprettySociable function.<br />
Here’s the complete settings object<br />
$.prettySociable({<br />
animationSpeed: &#8216;fast&#8217;, /* fast/slow/normal */<br />
opacity: 0.90, /* Value between 0 and 1 */<br />
share_label: &#8216;Drag to share&#8217;, /* Text displayed when a user rollover an item */<br />
share_on_label: &#8216;Share on &#8216;, /* Text displayed when a user rollover a website to share */<br />
hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettySociable */<br />
hover_padding: 0,<br />
websites: {<br />
facebook : {<br />
&#8216;active&#8217;: true,<br />
&#8216;encode&#8217;:true, // If sharing is not working, try to turn to false<br />
&#8216;title&#8217;: &#8216;Facebook&#8217;,<br />
&#8216;url&#8217;: &#8216;http://www.facebook.com/share.php?u=&#8217;,<br />
&#8216;icon&#8217;:'images/prettySociable/large_icons/facebook.png&#8217;,<br />
&#8216;sizes&#8217;:{&#8216;width&#8217;:70,&#8217;height&#8217;:70}<br />
},<br />
twitter : {<br />
&#8216;active&#8217;: true,<br />
&#8216;encode&#8217;:true, // If sharing is not working, try to turn to false<br />
&#8216;title&#8217;: &#8216;Twitter&#8217;,<br />
&#8216;url&#8217;: &#8216;http://twitter.com/home?status=&#8217;,<br />
&#8216;icon&#8217;:'images/prettySociable/large_icons/twitter.png&#8217;,<br />
&#8216;sizes&#8217;:{&#8216;width&#8217;:70,&#8217;height&#8217;:70}<br />
},<br />
delicious : {<br />
&#8216;active&#8217;: true,<br />
&#8216;encode&#8217;:true, // If sharing is not working, try to turn to false<br />
&#8216;title&#8217;: &#8216;Delicious&#8217;,<br />
&#8216;url&#8217;: &#8216;http://del.icio.us/post?url=&#8217;,<br />
&#8216;icon&#8217;:'images/prettySociable/large_icons/delicious.png&#8217;,<br />
&#8216;sizes&#8217;:{&#8216;width&#8217;:70,&#8217;height&#8217;:70}<br />
},<br />
digg : {<br />
&#8216;active&#8217;: true,<br />
&#8216;encode&#8217;:true, // If sharing is not working, try to turn to false<br />
&#8216;title&#8217;: &#8216;Digg&#8217;,<br />
&#8216;url&#8217;: &#8216;http://digg.com/submit?phase=2&amp;url=&#8217;,<br />
&#8216;icon&#8217;:'images/prettySociable/large_icons/digg.png&#8217;,<br />
&#8216;sizes&#8217;:{&#8216;width&#8217;:70,&#8217;height&#8217;:70}<br />
}<br />
//add more social networks here<br />
},<br />
tooltip: {<br />
offsetTop:0,<br />
offsetLeft: 10<br />
},<br />
popup: {<br />
width: 900,<br />
height: 500<br />
},<br />
callback: function(){} /* Called when prettySociable is closed */<br />
});<br />
The settings object is self explaining. You can specify which websites to use and also the icons to use for each website in the websites parameter.<br />
Learning jQuery: Better Interaction Design and Web Development with Simple JavaScript Techniques<br />
You can enhance this drag n share script even further by using a shortened URL in the anchor tag’s href attribute.</a></p>
<div id="seo_alrp_related"><h2>Posts Related to Quick & Easy Way to Implement Drag n Share With jQuery</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/importance-of-top-59-social-bookmarking-websites/" rel="bookmark">Importance of Top 59 Social Bookmarking Websites</a></h3><p>If your a blogger or website owner dont miss to understand the importance of social bookmarking, its a free web promotion technique.Social bookmarking site are ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/jquery-mouseover-tooltip-plugin/" rel="bookmark">Jquery Mouseover Tooltip Plugin</a></h3><p>Let's review a topic about how to create Jquery Mouseover Tooltip Plugin. Have you ever seen Jquery Mouseover Tooltip Plugin ? ... Like this below: ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/5-jquery-calendar-plugins-that-can-be-used-on-websites/" rel="bookmark">5 jQuery Calendar Plugins that can be used on Websites</a></h3><p>Online calendars can be very useful to share and publish your schedules. One of the most common requests I receive from my jQuery readers is ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/jquery-dialog-box-tutorial/" rel="bookmark">jQuery Dialog Box Tutorial</a></h3><p>Recently on a coding project for my day job I had a requirement to display a dialog box to confirm that when someone clicked a ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/add-a-%e2%80%9cread-more%e2%80%9d-link-using-jquery/" rel="bookmark">Add a “Read More” Link using jQuery</a></h3><p>The jQuery Expander Plugin is a simple little jQuery plugin to hide/collapse a portion of an element's text and add a "read more" link so ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/quick-easy-way-to-implement-drag-n-share-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a Twitter AJAX Button with MooTools, jQuery, or Dojo</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/create-a-twitter-ajax-button-with-mootools-jquery-or-dojo/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/create-a-twitter-ajax-button-with-mootools-jquery-or-dojo/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 17:22:42 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[MooTools]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=930</guid>
		<description><![CDATA[There&#8217;s nothing like a subtle, slick website widget that effectively uses CSS and JavaScript to enhance the user experience.  Of course widgets like that take many hours to perfect, but it doesn&#8217;t take long for that effort to be rewarded with above-average user retention and buzz. One of the widgets I love is Twitter&#8217;s &#8220;Follow&#8221; [...]]]></description>
			<content:encoded><![CDATA[<div>There&#8217;s nothing like a subtle, slick website widget that effectively uses CSS and JavaScript to enhance the user experience.  Of course widgets like that take many hours to perfect, but it doesn&#8217;t take long for that effort to be rewarded with above-average user retention and buzz.</div>
<p><a name="more"></a></p>
<div>One of the widgets I love is Twitter&#8217;s &#8220;Follow&#8221; button.  Let me show you how you can implement this functionality with three popular JavaScript toolkits:  MooTools, jQuery, and Dojo.</div>
<div><em>Note:  This tutorial will only display the client side handling of the form submission — NOT any PHP/MySQL/server-side handling of the request.</em></div>
<div><em><br />
</em></div>
<h2>The HTML Structure</h2>
<div>
<div>&lt;form method=&#8221;post&#8221; action=&#8221;twitter-follow.php&#8221;&gt;</div>
<div>&lt;input type=&#8221;hidden&#8221; name=&#8221;followID&#8221; value=&#8221;123456&#8243;&gt;</div>
<div>&lt;button type=&#8221;submit&#8221; value=&#8221;Actions&#8221; title=&#8221;123456&#8243;&gt;</div>
<div>&lt;i&gt;&lt;/i&gt;&lt;span&gt;follow&lt;/span&gt;</div>
<div>&lt;/button&gt;</div>
<div>&lt;/form&gt;</div>
</div>
<div>The HTML for the button is very simple.  The structure revolves around a BUTTON element which contains an I element and SPAN element.  You&#8217;re probably thinking &#8220;An I element?  WTF.&#8221;  I know I did.  The truth of the matter is that the I element is deprecated and, as far as I&#8217;m concerned, and be used for any purpose the developer would like.  I&#8217;m also sure that Twitter doesn&#8217;t mind saving bytes here or there</div>
<div>
<h2>The CSS Styles</h2>
<div>
<div>/* twitter button and its children */</div>
<div>button.btn {</div>
<div>-moz-border-radius:4px;</div>
<div>-webkit-border-radius:4px;</div>
<div>background-attachment:scroll;</div>
<div>background-color:#ddd;</div>
<div>background-image:url(http://s.twimg.com/a/1282150308/images/buttons/bg-btn.gif);</div>
<div>background-position:0 0;</div>
<div>background-repeat:repeat-x;</div>
<div>border:1px solid #ddd;</div>
<div>border-bottom:1px solid #ccc;</div>
<div>color:#333;</div>
<div>cursor:pointer;</div>
<div>font-family:&#8221;Lucida Grande&#8221;,sans-serif;</div>
<div>font-size:11px;</div>
<div>line-height:14px;</div>
<div>padding:4px 8px 5px 8px;</div>
<div>text-shadow:1px 1px 0 #fff;</div>
<div>vertical-align:top;</div>
<div>}</div>
<div>button.btn:hover {</div>
<div>border:1px solid #999;</div>
<div>border-bottom-color:#888;</div>
<div>color:#000;</div>
<div>background-color:#d5d5d5;</div>
<div>background-position:0 -6px;</div>
<div>}</div>
<div>button.btn:active {</div>
<div>background-image:none !important;</div>
<div>text-shadow:none !important;</div>
<div>}</div>
<div>button.btn i {</div>
<div>background-image:url(http://s.twimg.com/a/1282150308/images/sprite-icons.png);</div>
<div>background-position:-176px -32px;</div>
<div>background-repeat:no-repeat;</div>
<div>display:inline-block;</div>
<div>height:13px;</div>
<div>margin-right:5px;</div>
<div>width:15px;</div>
<div>}</div>
<div>button.btn i.active { background:url(http://s.twimg.com/a/1282150308/images/spinner.gif); }</div>
<div>/* properties for the element that is generated *after* following */</div>
<div>span.following {  background:#ffd; padding:5px 10px; }</div>
<div>span.following span { width:10px; height:9px; margin-right:5px; display:inline-block; background:url(&#8220;http://s.twimg.com/a/1282150308/images/sprite-icons.png&#8221;) -160px -16px no-repeat; }</div>
</div>
</div>
<div>Most of the styling for this button goes onto the BUTTON element itself.  You&#8217;ll notice directives to round the button;  leaving the button sharp also please the eye.  Through the regular, hover, and active button states, check out how Twitter users the background position and colors to nicely modify the button without the need for additional images.  You&#8217;ll also notice Twitter uses sprites&#8230;as should you.</div>
<div>
<h2>The MooTools JavaScript</h2>
<div>
<div>/* with mootools */</div>
<div>window.addEvent(&#8216;domready&#8217;,function() {</div>
<div>/* fetch elements */</div>
<div>$$(&#8216;form.follow-form&#8217;).each(function(form) {</div>
<div>/* stop form event */</div>
<div>form.addEvent(&#8216;submit&#8217;,function(e) {</div>
<div>/* stop event */</div>
<div>if(e) e.stop();</div>
<div>/* send ajax request */</div>
<div>var i = form.getElement(&#8216;i&#8217;);</div>
<div>new Request({</div>
<div>url: &#8216;twitter-follow.php&#8217;,</div>
<div>method: &#8216;post&#8217;,</div>
<div>data: {</div>
<div>followID: form.getElement(&#8216;input&#8217;).value</div>
<div>},</div>
<div>onRequest: function() {</div>
<div>i.addClass(&#8216;active&#8217;);</div>
<div>},</div>
<div>onSuccess: function() {</div>
<div>var button = form.getElement(&#8216;button&#8217;);</div>
<div>button.setStyle(&#8216;display&#8217;,'none&#8217;);</div>
<div>new Element(&#8216;span&#8217;,{</div>
<div>html: &#8216;&lt;span&gt;&lt;/span&gt;Following!&#8217;,</div>
<div>&#8216;class&#8217;: &#8216;following&#8217;</div>
<div>}).inject(button,&#8217;after&#8217;);</div>
<div>},</div>
<div>onComplete: function() {</div>
<div>i.removeClass(&#8216;active&#8217;);</div>
<div>}</div>
<div>}).send();</div>
<div>});</div>
<div>});</div>
<div>});</div>
</div>
<div>
<div>The first step is grabbing all of the FORM elements with the follow-form CSS class.  Upon form submission, the default submission action is stopped.  An AJAX request is fired, using the INPUT element&#8217;s ID as the user to follow.  When the request is fired, the I element&#8217;s background image is set to the spinner.  When the request is complete, the button is hidden and a new SPAN element is displayed informing the user that they are now following the given user!</div>
<h2>The jQuery JavaScript</h2>
</div>
<div>
<div>// Idiomatic jQuery by Doug Neiner</div>
<div>jQuery(function ($) {</div>
<div>/* fetch elements and stop form event */</div>
<div>$(&#8220;form.follow-form&#8221;).submit(function (e) {</div>
<div>/* stop event */</div>
<div>e.preventDefault();</div>
<div>/* &#8220;on request&#8221; */</div>
<div>$(this).find(&#8216;i&#8217;).addClass(&#8216;active&#8217;);</div>
<div>/* send ajax request */</div>
<div>$.post(&#8216;twitter-follow.php&#8217;, {</div>
<div>followID: $(this).find(&#8216;input&#8217;).val()</div>
<div>}, function () {</div>
<div>/* find and hide button, create element */</div>
<div>$(e.currentTarget)</div>
<div>.find(&#8216;button&#8217;).hide()</div>
<div>.after(&#8216;&lt;span&gt;&lt;span&gt;&lt;/span&gt;Following!&lt;/span&gt;&#8217;);</div>
<div>});</div>
<div>});</div>
<div>});</div>
</div>
<div>
<div>The code above is based off of the MooTools code.  The workflow is exactly the same.</div>
<h2>The Dojo JavaScript</h2>
</div>
<div>
<div>/* when the DOM is ready */</div>
<div>dojo.ready(function() {</div>
<div>/* fetch elements */</div>
<div>dojo.query(&#8216;form.follow-form&#8217;).forEach(function(form) {</div>
<div>/* stop form event */</div>
<div>dojo.connect(form,&#8217;onsubmit&#8217;,function(e) {</div>
<div>/* stop event */</div>
<div>dojo.stopEvent(e);</div>
<div>/* active class */</div>
<div>dojo.query(&#8216;i&#8217;,form).addClass(&#8216;active&#8217;);</div>
<div>/* get button */</div>
<div>var button = dojo.query(&#8216;button&#8217;,form)[0];</div>
<div>/* ajax request */</div>
<div>dojo.xhrPost({</div>
<div>form: form,</div>
<div>load: function() {</div>
<div>dojo.style(button,&#8217;display&#8217;,'none&#8217;);</div>
<div>dojo.create(&#8216;span&#8217;,{</div>
<div>innerHTML: &#8216;&lt;span&gt;&lt;/span&gt;Following&#8217;,</div>
<div>className: &#8216;following&#8217;</div>
<div>},button,&#8217;after&#8217;);</div>
<div>}</div>
<div>});</div>
<div>});</div>
<div>});</div>
<div>});</div>
</div>
<div>The code above is based off of the MooTools code.  The workflow is exactly the same.</div>
<div>This &#8220;Follow&#8221; button is only one of many details that Twitter has paid attention to, just to make the user experience on the site better.  Take note from the effort put forth by large websites — adding these types of details to your smaller websites can make the user experience much better for YOUR users!</div>
</div>
<div id="seo_alrp_related"><h2>Posts Related to Create a Twitter AJAX Button with MooTools, jQuery, or Dojo</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/change-background-color-of-asp-net-button-using-jquery/" rel="bookmark">Change Background Color of ASP.NET Button using jQuery</a></h3><p>Here’s a simple piece of code that can change the background color of an HTML or ASP.NET Button using jQuery ASP.NET Button &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/color-palette-generator-using-jqueryas-i-continue-to-learn-jquery-i-think-its-important-that-i-begin-by-porting-over-scripts-ive-created-using-mootools-one-of-those-scripts-is-my-color-palette-g/" rel="bookmark">Color Palette Generator Using jQueryAs I continue to learn jQuery, I think it&#8217;s important that I begin by porting over scripts I&#8217;ve created using MooTools. One of those scripts is my Color Palette Generator script, which debuted on Eric Wendelin&#8217;s blog. For those of you that missed it, my script analyzes all of the colors on the page (minus images) and builds a palette of colors. Here it is in some jQuery goodness.  The XHTML  <input type="button" id="get-colors" value="Get Colors" class="button" /> <div id="colors-wrapper"></div>  All we need to begin with is the button that triggers the palette generation and a DIV container that will hold all of the DIVs my jQuery creates. The CSS  .dcolor { height:40px; } .dtext {  } .dwrapper { width:200px; float:left; padding:10px; margin:0 20px 20px 0; border:1px solid #ccc; }   These CSS classes act as containers for the text DIV I generate and the color-displaying DIV I generate. Those two DIVs are held in one wrapping DIV. The jQuery JavaScript  /* when the dom is ready */ $(document).ready(function() { $(&#8216;#get-colors&#8217;).click(function() {   //my colors array var colors = new Array(); //get all elements $(&#8216;*&#8217;).each(function() { if($(this).css(&#8216;background-color&#8217;) &#038;&#038; $(this).css(&#8216;background-color&#8217;) != &#8216;transparent&#8217;) { colors.push($(this).css(&#8216;background-color&#8217;)); } if($(this).css(&#8216;color&#8217;)) { colors.push($(this).css(&#8216;color&#8217;)); } if($(this).css(&#8216;border-color&#8217;)) { colors.push($(this).css(&#8216;border-color&#8217;)); } }); //remove dupes and sort colors.sort(); //create a color block for all of them jQuery.each(colors,function(it,value) { if(!$(&#8216;div[rel=\'' + value + '\']&#8216;).length) { //inject the wrapper var wrapper_id = &#8216;w&#8217; + it; $(&#8216;<div class="dwrapper" id="' + wrapper_id + '" rel="' + value + '"> </div>&#8216;).appendTo(&#8216;#colors-wrapper&#8217;); //inject the color div $(&#8216;<div class="dcolor" style="background-color:' + value + '"> </div>&#8216;).appendTo(&#8216;#&#8217; + wrapper_id); //inject text div $(&#8216;<div class="text">&#8216; + value + &#8216;</div>&#8216;).appendTo(&#8216;#&#8217; + wrapper_id); } }); }); });   When someone clicks the &#8220;Get Colors&#8221; button, I grab every element in the DOM and collect its color, background-color, and border-color. Once I&#8217;ve cycled through all of the elements, cycle through all of the colors and display them as DIVs inside my colors-wrapper element. You&#8217;ll note that I utilized therel attribute to prevent duplicates.</a></h3><p>As I continue to learn jQuery, I think it's important that I begin by porting over scripts I've created using MooTools. One of those scripts ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-events-stop-working-in-asp-net-ajax-updatepanel/" rel="bookmark">jQuery events stop working in ASP.NET AJAX UpdatePanel</a></h3><p>In a recent forum discussion, a user was facing an issue where his jQuery events would stop working after a partial page postback. Here’s the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/all-fixed-fade-out-menu-a-css-and-jquery-tutorial/" rel="bookmark">all Fixed Fade Out Menu: A CSS and jQuery Tutorial</a></h3><p>1. The HTML The markup is pretty simple: we have a div with a list inside. The list items will be our links, the search ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/start-and-stop-an-animation-in-jquery/" rel="bookmark">Start and Stop an Animation in jQuery</a></h3><p>Starting and Stopping a jQuery Animation is as simple as using the animate() and stop() functions, as shown in the example below: &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/create-a-twitter-ajax-button-with-mootools-jquery-or-dojo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Load JSON data with jQuery, PHP and MySQL</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/load-json-data-with-jquery-php-and-mysql/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/load-json-data-with-jquery-php-and-mysql/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 17:20:32 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=927</guid>
		<description><![CDATA[This post shows how to populate a select box based on the value of the another, by getting JSON data with jQuery from a PHP script that gets the data from a MySQL database. HTML Code The initial HTML code looks like this: Fruit: Apple Orange Banana Pear Variety: The set of fruit names was [...]]]></description>
			<content:encoded><![CDATA[<p>This post shows how to populate a select box based on the value of the another, by getting JSON data with jQuery from a PHP script that gets the data from a MySQL database.</p>
<p>HTML Code<br />
The initial HTML code looks like this:</p>
<form> Fruit:</p>
<select id="fruitName" name="name">
<option>Apple</option>
<option>Orange</option>
<option>Banana</option>
<option>Pear</option>
</select>
<p>Variety:</p>
<select id="fruitVariety" name="variety"> </select>
</p></form>
<p>The set of fruit names was already populated on the server-side and the default set of varieties could be too; I have chosen to populate them with Javascript in this example.<br />
jQuery Code<br />
The jQuery code needs to initially populate the variety drop down based on the value of the fruit drop down. It then needs to update the variety if the fruit drop down changes.<br />
Assuming the PHP script to fetch the fruit is at /fruit-varieties.php do this:</p>
<p>function populateFruitVariety() {<br />
$.getJSON(&#8216;/fruit-varities.php&#8217;, {fruitName:$(&#8216;#fruitName&#8217;).val()}, function(data) {<br />
var select = $(&#8216;#fruitVariety&#8217;);<br />
var options = select.attr(&#8216;options&#8217;);<br />
options[options.length] =<br />
$(&#8216;option&#8217;, select).remove();</p>
<p>$.each(data, function(index, array) {</p>
<p>new Option(array['variety']);<br />
});</p>
<p>populat<br />
});</p>
<p>}</p>
<p>$(document).ready(function() {</p>
<p>eFruitVariety();<br />
$(&#8216;#fruitName&#8217;).change(function() {<br />
populateFruitVariety();<br />
});</p>
<p>});</p>
<p>The &#8220;$.getJSON(&#8216;/fruit-varities.php&#8217;, {fruitName:$(&#8216;#fruitName&#8217;).val()}&#8221; line is what retrieves the data and it passes the currently selected fruit name value as part of the get string to the PHP script.<br />
PHP Code<br />
The PHP script connects to the database, retrieves the data for the selected fruit name and then returns it as a JSON encoded string.</p>
<p>$dsn = &#8220;mysql:host=localhost;dbname=[DATABASE NAME HERE]&#8220;;<br />
$username = &#8220;[USERNAME HERE]&#8220;;<br />
$pdo = new PDO($dsn, $usernam<br />
$password = &#8220;[PASSWORD HERE]&#8220;;<br />
e, $password);</p>
<p>{     $stmt = $p<br />
$rows = array();<br />
if(isset($_GET['fruitName']))<br />
do-&gt;prepare(&#8220;SELECT variety FROM fruit WHERE name = ? ORDER BY variety&#8221;);<br />
$stmt-&gt;execute(array($_GET['fruitName']));<br />
} echo json_encode($rows);<br />
$rows = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);</p>
<p>Caching issues<br />
Internet Explorer and Firefox will cache the subsequent requests made to the same fruit name but the other browsers won&#8217;t, requesting them again each time.<br />
Further reading<br />
I haven&#8217;t written much in the way of comments for each of the above code snippets; they&#8217;ve all been covered to some degree in previous posts which led up to this one. Please refer to these in the  &#8220;Related Posts&#8221; list below.</p>
<div id="seo_alrp_related"><h2>Posts Related to Load JSON data with jQuery, PHP and MySQL</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/json-in-5-seconds/" rel="bookmark">JSON in 5 seconds</a></h3><p></p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/using-jquery-ajax-to-call-asp-net-json-web-service/" rel="bookmark">Using jQuery Ajax to call ASP.NET JSON web service</a></h3><p>The jQuery Ajax infrastructure allows you to perform asynchronous HTTP requests which makes it easy to call an ASP.NET JSON web service, using this api. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/creating-parsing-json-data-php/" rel="bookmark">Creating and Parsing JSON data with PHP</a></h3><p>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. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-connect-to-mysql-database-using-php/" rel="bookmark">How to Connect to MySQL Database Using PHP?</a></h3><p>&lt;?php $username = "your_name"; $password = "your password"; $hostname = "localhost"; $dbname = "database name"; //Connection to the MySql Database $dbhandle = mysql_connect($hostname, $username, $password) ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/load-json-data-with-jquery-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery UI DatePicker: Disable Specified Days</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/jquery-ui-datepicker-disable-specified-days/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/jquery-ui-datepicker-disable-specified-days/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 17:18:49 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=925</guid>
		<description><![CDATA[One project I&#8217;m currently working on requires jQuery. The project also features a datepicker for requesting a visit to their location. jQuery UI&#8217;s DatePicker plugin was the natural choice and it does a really nice job. One challenge I encountered was the need to prevent specific days from being picked. Here&#8217;s the jQuery JavaScript I [...]]]></description>
			<content:encoded><![CDATA[<div>One project I&#8217;m currently working on requires jQuery. The project also features a datepicker for requesting a visit to their location. jQuery UI&#8217;s DatePicker plugin was the natural choice and it does a really nice job. One challenge I encountered was the need to prevent specific days from being picked. Here&#8217;s the jQuery JavaScript I used to accomplish that.</div>
<p><a name="more"></a></p>
<p><br id="__mce" /></p>
<h2>The jQuery JavaScript</h2>
<div>
<div>/* create an array of days which need to be disabled */</div>
<div>var disabledDays = ["2-21-2010","2-24-2010","2-27-2010","2-28-2010","3-3-2010","3-17-2010","4-2-2010","4-3-2010","4-4-2010","4-5-2010"];</div>
<div>/* utility functions */</div>
<div>function nationalDays(date) {</div>
<div>var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();</div>
<div>//console.log(&#8216;Checking (raw): &#8216; + m + &#8216;-&#8217; + d + &#8216;-&#8217; + y);</div>
<div>for (i = 0; i &lt; disabledDays.length; i++) {</div>
<div>if($.inArray((m+1) + &#8216;-&#8217; + d + &#8216;-&#8217; + y,disabledDays) != -1 || new Date() &gt; date) {</div>
<div>//console.log(&#8216;bad:  &#8217; + (m+1) + &#8216;-&#8217; + d + &#8216;-&#8217; + y + &#8216; / &#8216; + disabledDays[i]);</div>
<div>return [false];</div>
<div>}</div>
<div>}</div>
<div>//console.log(&#8216;good:  &#8217; + (m+1) + &#8216;-&#8217; + d + &#8216;-&#8217; + y);</div>
<div>return [true];</div>
<div>}</div>
<div>function noWeekendsOrHolidays(date) {</div>
<div>var noWeekend = jQuery.datepicker.noWeekends(date);</div>
<div>return noWeekend[0] ? nationalDays(date) : noWeekend;</div>
<div>}</div>
<div>/* create datepicker */</div>
<div>jQuery(document).ready(function() {</div>
<div>jQuery(&#8216;#date&#8217;).datepicker({</div>
<div>minDate: new Date(2010, 0, 1),</div>
<div>maxDate: new Date(2010, 5, 31),</div>
<div>dateFormat: &#8216;DD, MM, d, yy&#8217;,</div>
<div>constrainInput: true,</div>
<div>beforeShowDay: noWeekendsOrHolidays</div>
<div>});</div>
<div>});</div>
</div>
<div>The base code is taken from this forum post. You&#8217;ll note that I created an array of dates in string format which also accommodates for comparing year.</div>
<div>I&#8217;d like to see jQuery UI implement a standard way of disabling days. Their DatePicker is very nice though so I can&#8217;t complain too much!</div>
<div id="seo_alrp_related"><h2>Posts Related to jQuery UI DatePicker: Disable Specified Days</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-ui-datepicker-date-range/" rel="bookmark">jQuery UI DatePicker Date Range</a></h3><p>In this post, I will show you how to specify Date Range for the jQuery UI DatePicker control, using the maxDate and minDate options. The ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/choose-which-dates-are-selectable-in-the-jquery-datepicker/" rel="bookmark">Choose which Dates are Selectable in the jQuery DatePicker</a></h3><p>While using the DatePicker control for a client, they had a requirement where users should be able to select only weekends (Saturday, Sunday) from the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/jquery-datepicker-%e2%80%93-select-a-date-programmatically/" rel="bookmark">jQuery DatePicker – Select a Date Programmatically</a></h3><p>I have seen users asking how to programmatically select a date using jQuery UI DatePicker control. The DatePicker beforeShowDay event is ideal for this type ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/disable-certain-days-in-a-week-using-jquery-ui-datepicker/" rel="bookmark">Disable Certain Days In a Week using jQuery UI DatePicker</a></h3><p>A couple of days ago, I had posted on Prevent Users from Selecting Weekends using jQuery UI DatePicker Dominic mailed asking if it was possible ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/reduce-size-of-the-jquery-datepicker/" rel="bookmark">Reduce Size of the jQuery DatePicker</a></h3><p>I often use the jQuery ui-lightness theme for my DatePicker, which I feel is quite nice. However by default, the DatePicker layout is quite ‘explosive’ ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/jquery-ui-datepicker-disable-specified-days/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Color Palette Generator Using jQueryAs I continue to learn jQuery, I think it&#8217;s important that I begin by porting over scripts I&#8217;ve created using MooTools. One of those scripts is my Color Palette Generator script, which debuted on Eric Wendelin&#8217;s blog. For those of you that missed it, my script analyzes all of the colors on the page (minus images) and builds a palette of colors. Here it is in some jQuery goodness.  The XHTML     All we need to begin with is the button that triggers the palette generation and a DIV container that will hold all of the DIVs my jQuery creates. The CSS  .dcolor { height:40px; } .dtext {  } .dwrapper { width:200px; float:left; padding:10px; margin:0 20px 20px 0; border:1px solid #ccc; }   These CSS classes act as containers for the text DIV I generate and the color-displaying DIV I generate. Those two DIVs are held in one wrapping DIV. The jQuery JavaScript  /* when the dom is ready */ $(document).ready(function() { $(&#8216;#get-colors&#8217;).click(function() {   //my colors array var colors = new Array(); //get all elements $(&#8216;*&#8217;).each(function() { if($(this).css(&#8216;background-color&#8217;) &amp;&amp; $(this).css(&#8216;background-color&#8217;) != &#8216;transparent&#8217;) { colors.push($(this).css(&#8216;background-color&#8217;)); } if($(this).css(&#8216;color&#8217;)) { colors.push($(this).css(&#8216;color&#8217;)); } if($(this).css(&#8216;border-color&#8217;)) { colors.push($(this).css(&#8216;border-color&#8217;)); } }); //remove dupes and sort colors.sort(); //create a color block for all of them jQuery.each(colors,function(it,value) { if(!$(&#8216;div[rel=\&#039;&#039; + value + &#039;\&#039;]&#8216;).length) { //inject the wrapper var wrapper_id = &#8216;w&#8217; + it; $(&#8216; &#8216;).appendTo(&#8216;#colors-wrapper&#8217;); //inject the color div $(&#8216; &#8216;).appendTo(&#8216;#&#8217; + wrapper_id); //inject text div $(&#8216;&#8216; + value + &#8216;&#8216;).appendTo(&#8216;#&#8217; + wrapper_id); } }); }); });   When someone clicks the &#8220;Get Colors&#8221; button, I grab every element in the DOM and collect its color, background-color, and border-color. Once I&#8217;ve cycled through all of the elements, cycle through all of the colors and display them as DIVs inside my colors-wrapper element. You&#8217;ll note that I utilized therel attribute to prevent duplicates.</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/color-palette-generator-using-jqueryas-i-continue-to-learn-jquery-i-think-its-important-that-i-begin-by-porting-over-scripts-ive-created-using-mootools-one-of-those-scripts-is-my-color-palette-g/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/color-palette-generator-using-jqueryas-i-continue-to-learn-jquery-i-think-its-important-that-i-begin-by-porting-over-scripts-ive-created-using-mootools-one-of-those-scripts-is-my-color-palette-g/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 17:17:51 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=923</guid>
		<description><![CDATA[As I continue to learn jQuery, I think it&#8217;s important that I begin by porting over scripts I&#8217;ve created using MooTools. One of those scripts is my Color Palette Generator script, which debuted on bagesh singh&#8217;s blog. For those of you that missed it, my script analyzes all of the colors on the page (minus images) [...]]]></description>
			<content:encoded><![CDATA[<div>As I continue to learn jQuery, I think it&#8217;s important that I begin by porting over scripts I&#8217;ve created using MooTools. One of those scripts is my Color Palette Generator script, which debuted on bagesh singh&#8217;s blog. For those of you that missed it, my script analyzes all of the colors on the page (minus images) and builds a palette of colors. Here it is in some jQuery goodness.</div>
<p><a name="more"></a></p>
<h2>The XHTML</h2>
<div></div>
<div>
<div>
<div>&lt;input type=&#8221;button&#8221; id=&#8221;get-colors&#8221; value=&#8221;Get Colors&#8221; /&gt;</div>
</div>
<div>
<div>&lt;div id=&#8221;colors-wrapper&#8221;&gt;&lt;/div&gt;</div>
</div>
</div>
<div></div>
<div>
<div>
<div>All we need to begin with is the button that triggers the palette generation and a DIV container that will hold all of the DIVs my jQuery creates.</div>
</div>
<h2>The CSS</h2>
<div></div>
<div>
<div>
<div>.dcolor  { height:40px; }</div>
</div>
<div>
<div>.dtext  {  }</div>
</div>
<div>
<div>.dwrapper { width:200px; float:left; padding:10px; margin:0 20px 20px 0; border:1px solid #ccc; }</div>
</div>
</div>
<div></div>
<div>
<div>
<div>These CSS classes act as containers for the text DIV I generate and the color-displaying DIV I generate. Those two DIVs are held in one wrapping DIV.</div>
</div>
<h2>The jQuery JavaScript</h2>
<div></div>
<div>
<div>
<div>/* when the dom is ready */</div>
</div>
<div>
<div>$(document).ready(function() {</div>
</div>
<div>
<div>$(&#8216;#get-colors&#8217;).click(function() {</div>
</div>
<div></div>
<div>
<div>//my colors array</div>
</div>
<div>
<div>var colors = new Array();</div>
</div>
<div></div>
<div>
<div>//get all elements</div>
</div>
<div>
<div>$(&#8216;*&#8217;).each(function() {</div>
</div>
<div>
<div>if($(this).css(&#8216;background-color&#8217;) &amp;&amp; $(this).css(&#8216;background-color&#8217;) != &#8216;transparent&#8217;) { colors.push($(this).css(&#8216;background-color&#8217;)); }</div>
</div>
<div>
<div>if($(this).css(&#8216;color&#8217;)) { colors.push($(this).css(&#8216;color&#8217;)); }</div>
</div>
<div>
<div>if($(this).css(&#8216;border-color&#8217;)) { colors.push($(this).css(&#8216;border-color&#8217;)); }</div>
</div>
<div>
<div>});</div>
</div>
<div></div>
<div>
<div>//remove dupes and sort</div>
</div>
<div>
<div>colors.sort();</div>
</div>
<div></div>
<div>
<div>//create a color block for all of them</div>
</div>
<div>
<div>jQuery.each(colors,function(it,value) {</div>
</div>
<div></div>
<div>
<div>if(!$(&#8216;div[rel=\'' + value + '\']&#8216;).length)</div>
</div>
<div>
<div>{</div>
</div>
<div></div>
<div>
<div>//inject the wrapper</div>
</div>
<div>
<div>var wrapper_id = &#8216;w&#8217; + it;</div>
</div>
<div>
<div>$(&#8216;&lt;div id=&#8221;&#8216; + wrapper_id + &#8216;&#8221; rel=&#8221;&#8216; + value + &#8216;&#8221;&gt; &lt;/div&gt;&#8217;).appendTo(&#8216;#colors-wrapper&#8217;);</div>
</div>
<div></div>
<div>
<div>//inject the color div</div>
</div>
<div>
<div>$(&#8216;&lt;div style=&#8221;background-color:&#8217; + value + &#8216;&#8221;&gt; &lt;/div&gt;&#8217;).appendTo(&#8216;#&#8217; + wrapper_id);</div>
</div>
<div></div>
<div>
<div>//inject text div</div>
</div>
<div>
<div>$(&#8216;&lt;div&gt;&#8217; + value + &#8216;&lt;/div&gt;&#8217;).appendTo(&#8216;#&#8217; + wrapper_id);</div>
</div>
<div>
<div>}</div>
</div>
<div></div>
<div>
<div>});</div>
</div>
<div></div>
<div>
<div>});</div>
</div>
<div>
<div>});</div>
</div>
</div>
<div></div>
</div>
<div></div>
</div>
<div>
<div>When someone clicks the &#8220;Get Colors&#8221; button, I grab every element in the DOM and collect its color, background-color, and border-color. Once I&#8217;ve cycled through all of the elements, cycle through all of the colors and display them as DIVs inside my colors-wrapper element. You&#8217;ll note that I utilized therel attribute to prevent duplicates.</div>
</div>
<div id="seo_alrp_related"><h2>Posts Related to Color Palette Generator Using jQueryAs I continue to learn jQuery, I think it's important that I begin by porting over scripts I've created using MooTools. One of those scripts is my Color Palette Generator script, which debuted on Eric Wendelin's blog. For those of you that missed it, my script analyzes all of the colors on the page (minus images) and builds a palette of colors. Here it is in some jQuery goodness.  The XHTML  <input type="button" id="get-colors" value="Get Colors" class="button" /> <div id="colors-wrapper"></div>  All we need to begin with is the button that triggers the palette generation and a DIV container that will hold all of the DIVs my jQuery creates. The CSS  .dcolor { height:40px; } .dtext {  } .dwrapper { width:200px; float:left; padding:10px; margin:0 20px 20px 0; border:1px solid #ccc; }   These CSS classes act as containers for the text DIV I generate and the color-displaying DIV I generate. Those two DIVs are held in one wrapping DIV. The jQuery JavaScript  /* when the dom is ready */ $(document).ready(function() { $('#get-colors').click(function() {   //my colors array var colors = new Array(); //get all elements $('*').each(function() { if($(this).css('background-color') && $(this).css('background-color') != 'transparent') { colors.push($(this).css('background-color')); } if($(this).css('color')) { colors.push($(this).css('color')); } if($(this).css('border-color')) { colors.push($(this).css('border-color')); } }); //remove dupes and sort colors.sort(); //create a color block for all of them jQuery.each(colors,function(it,value) { if(!$('div[rel='' + value + '']').length) { //inject the wrapper var wrapper_id = 'w' + it; $('<div class="dwrapper" id="' + wrapper_id + '" rel="' + value + '"> </div>').appendTo('#colors-wrapper'); //inject the color div $('<div class="dcolor" style="background-color:' + value + '"> </div>').appendTo('#' + wrapper_id); //inject text div $('<div class="text">' + value + '</div>').appendTo('#' + wrapper_id); } }); }); });   When someone clicks the "Get Colors" button, I grab every element in the DOM and collect its color, background-color, and border-color. Once I've cycled through all of the elements, cycle through all of the colors and display them as DIVs inside my colors-wrapper element. You'll note that I utilized therel attribute to prevent duplicates.</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/create-a-twitter-ajax-button-with-mootools-jquery-or-dojo/" rel="bookmark">Create a Twitter AJAX Button with MooTools, jQuery, or Dojo</a></h3><p>There's nothing like a subtle, slick website widget that effectively uses CSS and JavaScript to enhance the user experience.  Of course widgets like that take ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/color-psychology-in-online-marketing/" rel="bookmark">Color Psychology in Online Marketing</a></h3><p>On the internet we don't deal with face to face selling. The internet is a visual and psychological medium. The words, or sales copy, on ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/remove-duplicate-elements-from-an-array-using-jquery/" rel="bookmark">Remove Duplicate Elements from an Array using jQuery</a></h3><p>A very useful jQuery function is the $.unique() that removes all duplicate elements from an array of DOM elements. However this function only works on ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/all-fixed-fade-out-menu-a-css-and-jquery-tutorial/" rel="bookmark">all Fixed Fade Out Menu: A CSS and jQuery Tutorial</a></h3><p>1. The HTML The markup is pretty simple: we have a div with a list inside. The list items will be our links, the search ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/using-jquery-to-find-out-elements-on-the-page-that-do-not-have-an-id-attribute/" rel="bookmark">Using jQuery to find out Elements on the Page that do not have an ID attribute</a></h3><p>In this post, I will demo a simple selector to find out elements on the page that do not have an ID attribute declared on ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/color-palette-generator-using-jqueryas-i-continue-to-learn-jquery-i-think-its-important-that-i-begin-by-porting-over-scripts-ive-created-using-mootools-one-of-those-scripts-is-my-color-palette-g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax login validation system in PHP using jQuery</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/ajax-login-validation-php-jquery/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/ajax-login-validation-php-jquery/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 14:59:59 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=865</guid>
		<description><![CDATA[Last time, I’ve showed you how to check user availability in Ajax using jQuery’s fading effect. But I’ve just shown the example without connecting the database and some people have faced problem with database connecting solution of that problem.In this post, I’ll show you how to use Ajax login system in php using jQuery and [...]]]></description>
			<content:encoded><![CDATA[<p>Last time, I’ve showed you how to check user availability in Ajax using jQuery’s fading effect. But I’ve just shown the example without connecting the database and some people have faced problem with database connecting solution of that problem.In this post, I’ll show you how to use Ajax login system in php using jQuery and some animation as well.</p>
<p><strong> </strong></p>
<p>In this example, first of all we’ll validate the user login detail from ajax showing the messages with some animation. If authenticated, the user will be redirected to the secure page “secure.php”. If you’ll try to directly access “secure.php”, you can’t do that.</p>
<p>Now let’s look at the code how to do this,</p>
<p><strong>HTML Code</strong></p>
<pre>&lt; form method="post" action="" id="login_form" /&gt;
  &lt; input name="username" type="text" id="username" value="" maxlength="20" /&gt;
  &lt; input name="password" type="password" id="password" value="" maxlength="20" /&gt;
  &lt; input name="Submit" type="submit" id="submit" value="Login" /&gt;
&lt; /form &gt;</pre>
<p>As you can see in html code, we’ve created the form with id “login_form”.</p>
<p>And furthermore, the CSS code is same as the one available in the pervious post of checking user availability in ajax and php.</p>
<h4>JavaScript Code for Ajax Login validation system in PHP</h4>
<p>First of all we need to use the jQuery library in our code,</p>
<pre>&lt; script src="jquery.js" type="text/javascript" language="javascript"&gt;&lt;/script &gt;</pre>
<p>Now let’s look at the code in javaScript to call ajax and show the animated message with fading effects.</p>
<pre>$("#login_form").submit(function()
{
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("ajax_login.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
	  if(data=='yes') //if correct login detail
	  {
		$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
		{
 		  //add message and change the class of the box and start fading
		  $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
                  function()
		  {
  	  	     //redirect to secure page
		     document.location='secure.php';
		  });
		});
	  }
	  else
	  {
	  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
		{
		  //add message and change the class of the box and start fading
		  $(this).html('Your login detail sucks...').addClass('messageboxerror').fadeTo(900,1);
		});
          }
       });
       return false;//not to post the  form physically
});</pre>
<p>As you can see above this code is preety much similar to the previous post of checking username availability in ajax and php and you can see the explanation of the above code from that post. But in above code, where the user is validated, he’ll be logged into the “secure.php” using “document.location” in JavaScript.</p>
<pre>$("#password").blur(function()
{
	$("#login_form").trigger('submit');
});</pre>
<p>Well, as you can see above javaScript’s code, when focus is moved away from the password it also call the for sumit action. Basically whenever you hit tab button in password field, it starts validating the user detail using ajax.</p>
<h4>PHP Code for Ajax Login validation system</h4>
<p>First of all lets’s look at the code of the “ajax_login.php”.</p>
<pre>//get the posted values
$user_name=htmlspecialchars($_POST['user_name'],ENT_QUOTES);
$pass=md5($_POST['password']);
//now validating the username and password
$sql="SELECT user_name, password FROM tbl_user WHERE user_name='".$user_name."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//if username exists
if(mysql_num_rows($result)&gt;0)
{
	//compare the password
	if(strcmp($row['password'],$pass)==0)
	{
		echo "yes";
		//now set the session from here if needed
		$_SESSION['u_name']=$user_name;
	}
	else
		echo "no";
}
else
	echo "no"; //Invalid Login</pre>
<p>As you can see above, the user login detial is validated from the database. If the user login detail doesn’t exists, it just returns the “no” values and if the user login detial does exists the it just return “yes” values with setting username in session variable.</p>
<p>Finally,  let’s look at the code of <strong>secure.php</strong></p>
<pre>if(empty($_SESSION['u_name']))
  header("Location:index.html");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
  session_destroy();
  header("Location:index.html");
}
echo " &lt;a href='secure.php?logout'&gt;&lt;b&gt;Logout&lt;b&gt;&lt;/a&gt; ";
echo " &lt;div align='center'&gt;You Are inside secured Page&lt;/a&gt; ";</pre>
<p>As you can see above the code of “secure.php” is simpleforward. If the user is not authenticated by session then he’ll be redirected to “index.html”. And there is link for “logout” in this page form where user can destroy the seession.</p>
<p><strong><a href="http://roshanbh.com.np/codes/ajax-login-php.zip" target="_blank">Download Full Source Code</a> </strong></p>
<p><strong>Implementation Guide:</strong></p>
<p>To implement this code, dump the tbl_user “table” available in the zip file to your database and configure the database connection in “ajax_login.php”.</p>
<div id="seo_alrp_related"><h2>Posts Related to Ajax login validation system in PHP using jQuery</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-connect-to-mysql-database-using-php/" rel="bookmark">How to Connect to MySQL Database Using PHP?</a></h3><p>&lt;?php $username = "your_name"; $password = "your password"; $hostname = "localhost"; $dbname = "database name"; //Connection to the MySql Database $dbhandle = mysql_connect($hostname, $username, $password) ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-encrypt-passwords-in-the-database/" rel="bookmark">How to Encrypt Passwords in the Database</a></h3><p>If you are developing a password-protected web site, you have to make a decision about how to store user password information securely. What is "secure," ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/using-javascript-to-post-data-between-pages/" rel="bookmark">Using Javascript to POST Data Between Pages</a></h3><p>The following is a simple example of how to submit data from one HTML page to another using the POST method from Javascript. Normally, if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/visible-text-%e2%80%9cpassword%e2%80%9d-instead-of-%e2%80%9c%e2%80%9d-in-the-password-field/" rel="bookmark">Visible text</a></h3><p>As you know, the user login box of the website contains the following fields username and password. Furthermore, most of them put the</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/validate-ip-address-using-jquery/" rel="bookmark">Validate IP Address using jQuery</a></h3><p>I had recently posted on Add a Custom Validation Method to the jQuery Validation Plugin. A user asked me over twitter asking how to validate ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/ajax-login-validation-php-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery plugin: word-counter for textarea</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/jquery-plugin-word-counter-textarea/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/jquery-plugin-word-counter-textarea/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 10:43:03 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[jquery plugin]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=861</guid>
		<description><![CDATA[Sorry friends on the way of move to new home I’ve been lost from the blog as I didn’t have internet connection for few last weeks. Now, I’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[<p>Sorry friends on the way of move to new home I’ve been lost from the blog as I didn’t have internet connection for few last weeks. Now, I’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’ve developed jQuery plugin to display word-count of Textarea. Please note that it is word count plugin not character counter.</p>
<p><a href="http://roshanbh.com.np/examples/jquery-word-count-plugin/" target="_blank"><strong><br />
</strong></a></p>
<h4>Jquery plugin: Word-count code</h4>
<pre>jQuery.fn.wordCount = function(params)
{
   var p =  {
   counterElement:"display_count"
   };
  &amp;nbsp;var total_words;
  if(params) {
      jQuery.extend(p, params);
  &amp;nbsp;}
  //for each keypress function on text areas
 &amp;nbsp;this.keypress(function()
  {
    total_words=this.value.split(/[\s\.\?]+/).length;
   &amp;nbsp;jQuery('#'+p.counterElement).html(total_words);
  &amp;nbsp;});
};</pre>
<p><strong> </strong></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>&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 “word_count” and “display_count“.</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’ve just developed in the plugin of jQuery.</p>
<pre>$('#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’ve to override the value of variable <strong>counterElement</strong> which contains the id of element displaying word count.</p>
<pre>$('#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>
<div id="seo_alrp_related"><h2>Posts Related to jQuery plugin: word-counter for textarea</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/jquery-plugin-word-counter-for-textarea/" rel="bookmark">jQuery plugin: word-counter for textarea</a></h3><p>Sorry friends on the way of move to new home I</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/sliding-letters-with-jquery/" rel="bookmark">Sliding Letters with jQuery</a></h3><p>Example In the following we will go through an example and we’ll start by the html for a little menu: 1 &lt;div class="sl_examples"&gt; 2     &lt;a ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/add-a-%e2%80%9cread-more%e2%80%9d-link-using-jquery/" rel="bookmark">Add a “Read More” Link using jQuery</a></h3><p>The jQuery Expander Plugin is a simple little jQuery plugin to hide/collapse a portion of an element's text and add a "read more" link so ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/jquery-mouseover-tooltip-plugin/" rel="bookmark">Jquery Mouseover Tooltip Plugin</a></h3><p>Let's review a topic about how to create Jquery Mouseover Tooltip Plugin. Have you ever seen Jquery Mouseover Tooltip Plugin ? ... Like this below: ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/jpaginate-how-to-add-a-fancy-jquery-pagination-plugin/" rel="bookmark">jPaginate: how to add a Fancy jQuery Pagination Plugin</a></h3><p>jPaginate is a jQuery pagination plugin that comes with a twist: animated page numbers. The user can slide through the available page numbers by clicking ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/jquery-plugin-word-counter-textarea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expand-collapse toggle panel (div) using jquery</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/expandable-collapsible-toggle-pane-jquery/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/expandable-collapsible-toggle-pane-jquery/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 04:24:02 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[expandable pane]]></category>
		<category><![CDATA[toogle effect]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=841</guid>
		<description><![CDATA[In this post, I’ll show you how easy it is to show expandable and collapsible toggle panel using jQuery. When you click on the heading, the content gets displayed by sliding and when you again click on the heading again, it gets collapsed. View LIVE DEMO Now let’s look at the html code, &#60;div class="msg_list"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I’ll show you how easy it is to show expandable and collapsible toggle panel using jQuery. When you click on the heading, the content gets displayed by sliding and when you again click on the heading again, it gets collapsed.<br />
<strong>View LIVE DEMO</strong></p>
<p>Now let’s look at the html code,</p>
<pre>&lt;div class="msg_list"&gt;
&lt;p class="msg_head"&gt;Header-1 &lt;/p&gt;
&lt;div class="msg_body"&gt;
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit
&lt;/div&gt;
&lt;p class="msg_head"&gt;Header-2&lt;/p&gt;
&lt;div class="msg_body"&gt;
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit
&lt;/div&gt;
&lt;p class="msg_head"&gt;Header-3&lt;/p&gt;
&lt;div class="msg_body"&gt;
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit
&lt;/div&gt;
&lt;/div&gt;</pre>
<p>As you can see above, the whole message panes contained inside the div with class name “msg_list”. And, the header element where you click is defined with the class “msg_head” and after that there is element with class “msg_body” which contains the message or text which is expandable or collapsible.</p>
<p>Now let’s look at the CSS attributes of these three classes,</p>
<pre><span style="color: #ff00ff;">p {</span>
<span style="color: #333399;">padding: 0 0 1em;</span>
<span style="color: #ff00ff;">}</span>
<span style="color: #ff00ff;">.msg_list {</span>
<span style="color: #333399;">margin: 0px;
padding: 0px;
width: 383px;</span>
<span style="color: #ff00ff;">}</span>
<span style="color: #ff00ff;">.msg_head {</span>
<span style="color: #333399;">padding: 5px 10px;
cursor: pointer;
position: relative;
background-color:#FFCCCC;
margin:1px;</span>
<span style="color: #ff00ff;">}</span>
<span style="color: #ff00ff;">.msg_body {</span>
<span style="color: #333399;">padding: 5px 10px 15px;
background-color:#F4F4F8;</span>
<span style="color: #ff00ff;">}</span></pre>
<p>Now, let’s look at the JavaScript code to make the pane toggling i.e collapsible and expandable,</p>
<pre>&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
$(document).ready(function()
{
  //hide the all of the element with class msg_body
  $(".msg_body").hide();
  //toggle the componenet with class msg_body
  $(".msg_head").click(function()
  {
    $(this).next(".msg_body").slideToggle(600);
  });
});
&lt;/script&gt;</pre>
<p>As you can see above, first of all jQuery framework is used. After that, all the element with the class name “msg_body” is collapsed when the page is loaded. And you can see, the “slideToggle()” function of jQuery is used to expand and collapse the “div” with class “msg_body”. When user clicks on the element with the class “.msg_head”, then div with class “msg_body” next to it, gets toggled with sliding effect, making toggle panel using jQuery.</p>
<p><a href="http://roshanbh.com.np/codes/exapandable-panel.zip" target="_blank"><strong>Download Full Source Code</strong> </a></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 “<strong>jQuery in Action</strong>” for starting your way for jQuery.</p>
<div id="seo_alrp_related"><h2>Posts Related to Expand-collapse toggle panel (div) using jquery</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/create-a-dynamic-scrolling-content-box-using-ajax/" rel="bookmark">Create a Dynamic Scrolling Content Box Using AJAX</a></h3><p>If you have used Google Reader, then you might have noticed the way Google Reader shows feed items, it loads up few items first when ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/create-astonishing-ical-like-calendars-with-jquery/" rel="bookmark">Create astonishing iCal-like calendars with jQuery</a></h3><p>According to my web designer experience, one of the most common requests from clients when it comes to WordPress personalization, is to add a basic ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/expand-collapse-toggle-panel-div-using-jquery/" rel="bookmark">Expand-collapse toggle panel (div) using jquery</a></h3><p>In this post, I</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/07/jquery-thumbnail-image-with-heading-and-caption/" rel="bookmark">Jquery Thumbnail Image with Heading and Caption</a></h3><p>Let's review a topic about how to create a Jquery Thumbnail Image with Heading and Caption. Have you ever seen Jquery Thumbnail Image with Heading ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/add-a-%e2%80%9cread-more%e2%80%9d-link-using-jquery/" rel="bookmark">Add a “Read More” Link using jQuery</a></h3><p>The jQuery Expander Plugin is a simple little jQuery plugin to hide/collapse a portion of an element's text and add a "read more" link so ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/expandable-collapsible-toggle-pane-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

