<?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>Team Tutorials &#187; jquery</title>
	<atom:link href="http://teamtutorials.com/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://teamtutorials.com</link>
	<description></description>
	<lastBuildDate>Thu, 05 Apr 2012 19:38:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Using jQuery to Reorder a List and Update a Database</title>
		<link>http://teamtutorials.com/web-development-tutorials/using-jquery-to-reorder-a-list-and-update-a-database?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-jquery-to-reorder-a-list-and-update-a-database</link>
		<comments>http://teamtutorials.com/web-development-tutorials/using-jquery-to-reorder-a-list-and-update-a-database#comments</comments>
		<pubDate>Wed, 30 Sep 2009 21:05:23 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Reorder]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=2126</guid>
		<description><![CDATA[This tutorial will show you how to use jQuery to allow as list (UL) to be reordered and will also make an AJAX call to a PHP file that will update the database when an item is dropped. I found this useful for a project I was working on recently. The user wanted to be able to change the order that categories displayed in a report. The items are stored in a database with a field called display_order. When the report is generated we simply order by that field.]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to use jQuery to allow as list (UL) to be reordered and will also make an AJAX call to a PHP file that will update the database when an item is dropped. I found this useful for a project I was working on recently. The user wanted to be able to change the order that categories displayed in a report. The items are stored in a database with a field called display_order. When the report is generated we simply order by that field.</p>
<p><strong>This tutorial requires:</strong></p>
<ul>
<li>A web server that handles PHP and MySql or <a href="http://teamtutorials.com/web-development-tutorials/setting-up-a-wamp-server">setup a local  Windows Apache MySql Php web server.</a></li>
<li> <a href="http://jqueryui.com/download"> jQuery and jQuery UI</a>.
<li>Basic HTML/CSS/Javascript knowledge.</li>
</ul>
<p>First you are going to need to <a href="http://jqueryui.com/download" target=="blank">download jQuery Ui.</a> There are plenty of feature within jQuery User Interface that I will not be touching in this tutorial, but for sake of the tutorial download the entire bundle. Also I will be using the default (UI Lightness) theme.<br />
Create a folder for this project on your server. You will need to unzip the jQuery files and put them all in this directory.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-01.gif"><img src="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-01.gif" alt="jquery-reorder-tutorial-01" title="jquery-reorder-tutorial-01" width="700" height="417" class="alignnone size-full wp-image-2129" /></a></p>
<p>Since jQuery comes with an example called index.html I am going to name my file test.php. You can call it whatever you want. Create the file. We will use it later. We&#8217;ll set the database up first.</p>
<p>I like to use <a href=" http://www.heidisql.com/" target="blank">HeidiSQL</a> when working with MySQL. Now on the database server I am going to create a database call test_tutorials, with a table called report_items. Here are the field properties for the report_items table:<br />
<a href="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-02.gif"><img src="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-02.gif" alt="jquery-reorder-tutorial-02" title="jquery-reorder-tutorial-02" width="624" height="159" class="alignnone size-full wp-image-2130" /></a></p>
<p>Now populate your table with some test data. I&#8217;ll insert 6 rows. Also make sure you insert the display order starting from 0.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-03.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-03.jpg" alt="jquery-reorder-tutorial-03" title="jquery-reorder-tutorial-03" width="576" height="235" class="alignnone size-full wp-image-2131" /></a></p>
<p>You can save the changes to your data base and get back to working on test.php. Open the file. We&#8217;ll start with the basic layout. </p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Reorder Test&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Next we&#8217;ll include the stylesheet from our jQuery theme. I&#8217;ll also add some CSS from the example on the jQuery UI website. Then we&#8217;ll include the jQuery javascript files.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Reorder Test&lt;/title&gt;
&lt;/head&gt;

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;development-bundle/themes/base/ui.all.css&quot;/&gt;

&lt;style type=&quot;text/css&quot;&gt;
	#sortable {
		list-style-type: none;
		margin: 0;
		padding: 0;
		width: 60%;
	}
	#sortable li {
		margin: 0 3px 3px 3px;
		padding: 0.4em;
		padding-left: 1.5em;
		font-size: 1.4em;
		height: 18px;
	}
	#sortable li span {
		position: absolute;
		margin-left: -1.3em;
	}
&lt;/style&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt; &lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-ui-1.7.2.custom.min.js&quot;&gt;&lt;/script&gt;

&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>We are going to pull the intial data from the database. In order to do this we&#8217;ll need to make a database connection. Create a new file called connect.php and create a database connection (obvious added your credentials where needed.</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
&lt;?php

$servername='localhost'; //no need to change if the file is located on the same server
$dbusername='username'; //your db username
$dbpassword='password'; //your db password
$dbname='database'; //for this tutorial I called my db test_tutorials

connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword){
	global $link;
	$link=mysql_connect ($servername,$dbuser,$dbpassword);
	if(!$link){die(&quot;Could not connect to MySQL&quot;);}
	mysql_select_db($dbname,$link) or die (&quot;could not open db&quot;.mysql_error());
}

?&gt;
</pre>
<p>Save connect.php and include it into your test.php file:</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
&lt;?php include('connect.php');?&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Reorder Test&lt;/title&gt;
&lt;/head&gt;

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;development-bundle/themes/base/ui.all.css&quot;/&gt;

&lt;style type=&quot;text/css&quot;&gt;
	#sortable {
		list-style-type: none;
		margin: 0;
		padding: 0;
		width: 60%;
	}
	#sortable li {
		margin: 0 3px 3px 3px;
		padding: 0.4em;
		padding-left: 1.5em;
		font-size: 1.4em;
		height: 18px;
	}
	#sortable li span {
		position: absolute;
		margin-left: -1.3em;
	}
&lt;/style&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt; &lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-ui-1.7.2.custom.min.js&quot;&gt;&lt;/script&gt;

&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now we need to retrieve the database results and dsiplay them. The items will be display in an un-ordered list. We&#8217;ll add this code to the body.</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
&lt;body&gt;
	&lt;ul id=&quot;sortable&quot;&gt;
    &lt;?php
	$sql = &quot;select * from report_items order by Category_Display_Order ASC&quot;;
	$query = mysql_query($sql);

	while($row = mysql_fetch_array($query))
	{
		$catid = $row['Category_ID'];
		$catname = $row['Category_Name'];
		echo &quot;&lt;li id='item_$catid' class='ui-state-default'&gt;&lt;span class='ui-icon ui-icon-arrowthick-2-n-s'&gt;&lt;/span&gt;$catname&lt;/li&gt;&quot;;
	}

	?&gt;
    &lt;/ul&gt;
&lt;/body&gt; </pre>
<p>Take not above. When we echo the li we are adding the ui-state-default class which is just a jQuery theme class and the span that we included is an arrow icon also provide with jQuery Ui. Where you see item_$catid, that should be your primary key from your database (this will be used later to reorder items.</p>
<p>Now save the file and load it in your browser. If you followed everything hopefully you will get something like this:<br />
<a href="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-04.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-04.jpg" alt="jquery-reorder-tutorial-04" title="jquery-reorder-tutorial-04" width="700" height="183" class="alignnone size-full wp-image-2132" /></a></p>
<p>Now we&#8217;ll enable the sortable function on our list. Remeber I gave the UL tag an id of sortable. Add this code in the head below your jquery javascript files:</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
	$(function() {
		$(&quot;#sortable&quot;).sortable({
			placeholder: 'ui-state-highlight',
		});
		$(&quot;#sortable&quot;).disableSelection();
	});
&lt;/script&gt;
</pre>
<p>The code above enables sorting of the UL with the id #sortable. The placeholder: &#8216;ui-state-highlight&#8217; tells jquery we want it to show a place holder of where we can drop the item. In the them I am using it is a yellow box. Make the changes above and save your page. You should now be able to drap and drop your list items.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-05.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-05.jpg" alt="jquery-reorder-tutorial-05" title="jquery-reorder-tutorial-05" width="700" height="206" class="alignnone size-full wp-image-2133" /></a></p>
<p>Now that you have that working we can move to the AJAX call. When an item is dropped, we want to call a php file to update the database. We do that by using the stop: action. So when dragging stops, the script will call the url (updatedb.php) we provided below. To make the AJAZ called, we let jQuery do the work.</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
	$(function() {
		$(&quot;#sortable&quot;).sortable({
			placeholder: 'ui-state-highlight',
			stop: function(i) {
				placeholder: 'ui-state-highlight'
				$.ajax({
					type: &quot;GET&quot;,
					url: &quot;updatedb.php&quot;,
					data: $(&quot;#sortable&quot;).sortable(&quot;serialize&quot;)});
			}
		});
		$(&quot;#sortable&quot;).disableSelection();
	});
&lt;/script&gt;
</pre>
<p>You see the ajax function above. We tell it what type of request, in this case wer&#8217;ll use get variables. We also tell it what URL, this is a php file we&#8217;ll create to update the database. Then we add the data that will be sent. </p>
<p>The code $(&#8220;#sortable&#8221;).sortable(&#8220;serialize&#8221;)}); will take the items within our ordered list and serialize it. It will take the items of the list, in whatever order they are in, and turn them into a get variable. So for each item it will add it to an array and format is properly to make the call to the PHP file. The data will look like this:<br />
item[]=1&#038;item[]=2&#038;item[]=3&#038;item[]=4&#038;item[]=5&#038;item[]=6</p>
<p>If you want to debug AJAX request I recommend  using Firefox with the Firebug plugin. If you want to see that the request is being attempted and that what the data looks like, you can add an alert box just below the placeholder like this: alert($(&#8220;#sortable&#8221;).sortable(&#8220;serialize&#8221;));<br />
Save the changes to you file we are done with test.php. Here is my full source of test.php up to this point.</p>
<pre class="brush: plain; title: Code Snippet:; notranslate">
&lt;?php include('connect.php');?&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Reorder Test&lt;/title&gt;
&lt;/head&gt;

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;development-bundle/themes/base/ui.all.css&quot;/&gt;

&lt;style type=&quot;text/css&quot;&gt;
	#sortable {
		list-style-type: none;
		margin: 0;
		padding: 0;
		width: 60%;
	}
	#sortable li {
		margin: 0 3px 3px 3px;
		padding: 0.4em;
		padding-left: 1.5em;
		font-size: 1.4em;
		height: 18px;
	}
	#sortable li span {
		position: absolute;
		margin-left: -1.3em;
	}
&lt;/style&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-ui-1.7.2.custom.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	$(function() {
		$(&quot;#sortable&quot;).sortable({
			placeholder: 'ui-state-highlight',
			stop: function(i) {
				placeholder: 'ui-state-highlight'
				$.ajax({
					type: &quot;GET&quot;,
					url: &quot;updatedb.php&quot;,
					data: $(&quot;#sortable&quot;).sortable(&quot;serialize&quot;)});
			}
		});
		$(&quot;#sortable&quot;).disableSelection();
	});
&lt;/script&gt;
&lt;body&gt;
	&lt;ul id=&quot;sortable&quot;&gt;
    &lt;?php
	$sql = &quot;select * from report_items order by Category_Display_Order ASC&quot;;
	$query = mysql_query($sql);

	while($row = mysql_fetch_array($query))
	{
		$catid = $row['Category_ID'];
		$catname = $row['Category_Name'];
		echo &quot;&lt;li id='item_$catid' class='ui-state-default'&gt;&lt;span class='ui-icon ui-icon-arrowthick-2-n-s'&gt;&lt;/span&gt;$catname&lt;/li&gt;&quot;;
	}

	?&gt;
    &lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now we need to actually update the database. Create a file called updatedb.php. This file is pretty simple. We take each item in the array and then update the database based on the array position($key) and the primary key ($value)</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
&lt;?php
include('connect.php');

foreach($_GET['item'] as $key=&gt;$value) {
	mysql_query(&quot;UPDATE report_items SET Category_Display_Order = '$key' WHERE Categoryt_ID ='$value';&quot;);
}
?&gt; </pre>
<p>Save that file and test the reorder. If you have problems and you think it is with the AJAX call. Check fire bug. Here is an example of a bad request in this case I tried to include a file that was not there.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-06.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2009/09/jquery-reorder-tutorial-06.jpg" alt="jquery-reorder-tutorial-06" title="jquery-reorder-tutorial-06" width="700" height="277" class="alignnone size-full wp-image-2134" /></a></p>
<p><strong>I hope this tutorial helped someone out</strong></p>
<ul>
<li><a href="http://demos.teamtutorials.com/jquery_reoder_list/list_tutorial.rar">Download Source</a></li>
<li><a href="http://demos.teamtutorials.com/jquery_reoder_list/">View Live Demo (no database interaction)</a></li>
</ul>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://teamtutorials.com/web-development-tutorials/simple-php-website-templates" title="Simple PHP Website Templates">Simple PHP Website Templates</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/hide-and-show-a-div-using-javascript" title="Hide and Show a Div Using Javascript">Hide and Show a Div Using Javascript</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/installing-code-editor" title="Installing Code Editor">Installing Code Editor</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/how-to-return-mysql-results-to-a-table" title="How to Return MySQL Results to a Table">How to Return MySQL Results to a Table</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/using-jquery-to-reorder-a-list-and-update-a-database/feed</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>jQuery Pop Over Effects</title>
		<link>http://teamtutorials.com/web-development-tutorials/jquery-pop-over-effects?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-pop-over-effects</link>
		<comments>http://teamtutorials.com/web-development-tutorials/jquery-pop-over-effects#comments</comments>
		<pubDate>Sun, 07 Sep 2008 13:35:36 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[JavaScriptTutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1655</guid>
		<description><![CDATA[This tutorial we will create a pop over box using the jQuery Javascript Framework. I will demonstrate a few of the animation option in jQuery and discuss why you should or shouldn’t use them. ]]></description>
			<content:encoded><![CDATA[<p>This tutorial we will create a pop over box using the jQuery Javascript Framework. I will demonstrate a few of the animation option in jQuery and discuss why you should or shouldn’t use them. </p>
<p>Disclaimer:<br />
I will be using a transparent .png for this tutorial. Not all browsers handle the transparency right. Also some browsers, like Internet Explorer, will display the transparency fine if it is a normal image on a page. When you try to animate that image you will get the “halo” effect. You will see what I mean later. If you are using a browser that supports transparent .png file, you will need to find the .png fix for it. Here are some <a href="http://code.google.com/p/ie7-js/">png fixes for IE 5-7</a> , you can link directly to the files hosted at Google if you would like to.</p>
<p>Why jQuery? Basically I used jQuery here because it is fast and simple. You could accomplish all of the effects by writing you own Javasciprt, but why do that when the makers of jQuery have done it all for you?</p>
<p>First you will need to download the <a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.min.js&#038;downloadBtn=">latest version of jQuery</a>. At the time of the post the current version is called jquery-1.2.6.min.js. Save jQuery to the same folder you will be saving your html files to, I called mine jQuery.</p>
<p>Next we need to layout the page. I am not going to explain all of the code in this tutorial. If you don’t understand it please see our XHTML and CSS tutorials. The part that you will want to pay attention to is the pop up. Download the box.png file here (box.png):</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/09/box.png"><img src="http://teamtutorials.com/wp-content/uploads/2008/09/box.png" alt="" title="box" width="450" height="425" class="alignleft size-full wp-image-1656" /></a></p>
<p>Here is the source code for the page layout:</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;jQuery Pop In&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
#box
{
position: absolute;
top:25%;
left:25%;
width:50%;
text-align: center;
}

#form{
background: url('box.png') no-repeat;
width: 450px;
height: 425px;
margin: 0 auto;
}
--&gt;
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;a href=&quot;#&quot; id=&quot;in&quot;&gt;Fade Box&lt;/a&gt; &lt;!-- Button to Fade the div in --&gt;
&lt;a href=&quot;#&quot; id=&quot;show&quot;&gt;Show Box&lt;/a&gt; &lt;!-- Button to Simply show the box with no effect --&gt;
&lt;a href=&quot;#&quot; id=&quot;slide&quot;&gt;Slide Box&lt;/a&gt; &lt;!-- Button to slide the box in --&gt;

&lt;div id=&quot;box&quot;&gt; &lt;!-- This container centers the box in your browser windo --&gt;

&lt;div id=&quot;form&quot;&gt;&lt;/div&gt; &lt;!-- This is the actual box.--&gt;

&lt;/div&gt;&lt;!-- end #box--&gt;

&lt;/div&gt;&lt;!-- end #form--&gt;

&lt;!-- the rest is the basic page layout--&gt;
&lt;div id=&quot;page&quot;&gt;

&lt;h2&gt;This is the page&lt;/h2&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam porta quam eget
turpis placerat aliquam. Praesent eget metus. Aliquam fermentum, massa a pulvinar
sodales, justo velit consectetuer purus, at vehicula magna libero quis sapien.
Praesent molestie. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Vivamus id diam non metus euismod sollicitudin.
Duis lobortis leo vel dui. Nulla ultricies tortor at augue. Proin egestas feugiat nibh.
Maecenas a pede sed lorem vestibulum facilisis.&gt;/p&gt;

&lt;p&gt;Curabitur venenatis tempus risus. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Praesent elit. Donec imperdiet dapibus lorem. Mauris imperdiet lacinia
lacus. Aliquam pellentesque enim ut nisl. Pellentesque tristique, augue egestas porttitor
suscipit, lacus dui tempus dui, in commodo lacus mauris non tortor. Lorem ipsum dolor sit
amet, consectetuer adipiscing elit. Duis vel neque sed nibh pharetra adipiscing. Etiam
euismod rhoncus dui. Sed ut nulla. Quisque mollis.&lt;/p&gt;

&lt;p&gt;Praesent libero turpis, ultrices nec, blandit sed, cursus sed, augue. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec hendrerit
pretium elit. Donec eget dui in mauris lobortis viverra. Vestibulum pharetra, libero in
bibendum malesuada, ante ligula lobortis turpis, eu tempor turpis libero at lacus. Curabitur
semper, ligula non mattis semper, neque dolor fermentum arcu, quis vehicula ipsum mi sed libero.
Suspendisse potenti. Integer ut lacus nec sem hendrerit ornare. Nulla eros. Duis nec mauris.
Cras ac turpis vel ante venenatis consequat. Sed rutrum lobortis augue. Aenean mi lectus,
vulputate quis, rutrum in, pharetra id, dolor. Proin posuere pede vitae ipsum. Curabitur euismod
semper odio. Ut tristique scelerisque leo. Fusce at ante sit amet lorem pharetra viverra. In hac
habitasse platea dictumst.&lt;/p&gt;

&lt;p&gt;Curabitur id nunc. Cras euismod, orci sed eleifend tempus, massa lacus sodales metus, vitae
tristique augue elit a tortor. Vestibulum viverra, nisi id faucibus sodales, nunc dolor condimentum
eros, et accumsan velit orci ut dolor. Donec dolor dolor, porttitor nec, porta in, rutrum vel, leo.
Suspendisse erat eros, ultricies in, auctor in, pretium vel, ante. Aliquam erat volutpat.
Vestibulum auctor ipsum ut risus. Maecenas nec sapien. Nullam eget ipsum nec sapien ornare dapibus.
Pellentesque ligula. Pellentesque habitant morbi tristique senectus et netus et malesuada fames
ac turpis egestas. Integer ac pede. Phasellus eleifend malesuada nibh. Ut laoreet, mi a auctor
fermentum, magna lectus placerat ligula, a vestibulum sapien arcu non nunc. Vivamus tristique.
Vestibulum sagittis est.&lt;/p&gt;

&lt;p&gt;
Phasellus tincidunt neque et dui. Praesent sed enim. Aliquam gravida pulvinar quam. Class aptent
taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed vitae ante nec
tellus rutrum pharetra. Praesent sodales tempus magna. Vestibulum fermentum imperdiet leo. Praesent
vel augue. Proin at nisi. Etiam volutpat venenatis ipsum. Morbi venenatis. Mauris porta elementum velit.
Pellentesque nibh dolor, molestie in, ultrices at, accumsan sit amet, massa. &lt;/p&gt;
&lt;p/&gt;

&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>So as you see we have the page with our pop box open.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/09/javascript-pop-over-effect-02.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/09/javascript-pop-over-effect-02.jpg" alt="" title="javascript-pop-over-effect-02" width="500" height="413" class="alignnone size-full wp-image-1657" /></a></p>
<p>Make sure that everything looks right; the box is showing and center, etc. Now we don’t want this popup to show by default so we will hide it. In the CSS we will set the display value to none on the #box. Add the line ‘display: none;’ to the existing css code.</p>
<pre class="brush: css; title: Code Snippet:; notranslate">
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
#box
{
position: absolute;
top:25%;
left:25%;
width:50%;
text-align: center;
display: none;
}
</pre>
<p>Now the page should look like this.<br />
<a href="http://teamtutorials.com/wp-content/uploads/2008/09/javascript-pop-over-effect-03.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/09/javascript-pop-over-effect-03.jpg" alt="" title="javascript-pop-over-effect-03" width="500" height="412" class="alignnone size-full wp-image-1658" /></a></p>
<p>Now to add jQuery. First we need to call the jquery file in the head of our page. Add the line below the title and above the style tag like below.</p>
<pre class="brush: xml; title: Code Snippet:; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;jQuery Pop In&lt;/title&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.2.6.min.js&quot;&gt;&lt;/script&gt;

&lt;style type=&quot;text/css&quot;&gt;
…

Next we will create the code for our first link the “fade box” link. In the head we will add the following code just below our other javascript tag:

&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function(){

		$(&quot;a#in&quot;).click(function(event){
			$(&quot;div#box&quot;).fadeIn(&quot;slow&quot;);
		});

		$(&quot;div#box&quot;).click(function(event){
			$(&quot;div#box&quot;).hide();
		});

	});
&lt;/script&gt;
[/html]

What does the code do?

First we are only going to run the code when the document is ready. A lot of people will use the page load function, but I like to use document ready. All other code will be contained in this function.

This line calls the jquer on click function and passes the link with the id=”in” to it. You do not need to include the a, but I think it is easier to tell the named elements apart that way:
1

$(&quot;a#in&quot;).click(function(event){  
</pre>
<p>So jQuery will “watch” the page and when the link is clicked, it will run the next code. This code calls the fadeIn function. Capital I by the way. It is basically saying find #box and fade it in slowly:</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">

	$(&quot;div#box&quot;).fadeIn(&quot;slow&quot;);

});
</pre>
<p>For the speed of the function you could use “slow” or “fast”, but you can also set the speed in milliseconds such as fadIn(1000).</p>
<p>The next part of the code is saying that when you click on the box, make it disappear:</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">

		$(&quot;div#box&quot;).click(function(event){
			$(&quot;div#box&quot;).hide();
		});
</pre>
<p>Now you could use the .fadeOut function. I used hide for a reason and you will see why below.</p>
<p>The problems with the fade function and transparent .png files:<br />
Due to the way some browsers render the png you will get the halo effect:</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/09/javascript-pop-over-effect-04.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/09/javascript-pop-over-effect-04.jpg" alt="" title="javascript-pop-over-effect-04" width="500" height="148" class="alignnone size-full wp-image-1659" /></a></p>
<p>As far as I know there is no fix for this. That is why I usually just use the simple show/hide function.</p>
<p>The solution is to use the show/hide functions. We will ad the code for the show box button:</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">

&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function(){

		$(&quot;a#in&quot;).click(function(event){
			$(&quot;div#box&quot;).fadeIn(&quot;slow&quot;);
		});

		$(&quot;div#box&quot;).click(function(event){
			$(&quot;div#box&quot;).hide();
		});

		$(&quot;a#show&quot;).click(function(event){
				$(&quot;div#box&quot;).fadeIn(&quot;slow&quot;);
		});

	});
&lt;/script&gt;
</pre>
<p>Now when you click the show box button it will simple pop up with no effect.</p>
<p>Another effect is the slide down/up effect, works with the same parameters as the fade effect. Set this code to work when you click the slide button.</p>
<pre class="brush: jscript; title: Code Snippet:; notranslate">

		$(&quot;a#slide&quot;).click(function(event){
				$(&quot;div#box&quot;).slideDown(&quot;slow&quot;);
		});
</pre>
<p>The slide effect seems to work correctly in all of the browsers I have tested above. </p>
<p>This was a basic tutorial on some of the effects in jQuery. Here is the full source, images, and jquery code that was used in this tutorial.</p>
<p><a href='http://teamtutorials.com/wp-content/uploads/2008/09/jquery-effect-code.zip'>jquery-effect-code</a></p>
<p>If you have questions please ask. </p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://teamtutorials.com/web-development-tutorials/password-verification-and-strength-checker" title="Password Verification and Strength Checker">Password Verification and Strength Checker</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/dynamically-add-textbox-to-site" title="Dynamically Add Textbox to Site">Dynamically Add Textbox to Site</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/using-jquery-to-reorder-a-list-and-update-a-database" title="Using jQuery to Reorder a List and Update a Database">Using jQuery to Reorder a List and Update a Database</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/javascript-progress-bar-2" title="JavaScript Progress Bar 2">JavaScript Progress Bar 2</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/jquery-pop-over-effects/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

