<?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>Not A n00b &#187; jQuery</title>
	<atom:link href="http://notan00b.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://notan00b.com</link>
	<description>Tutorials, Scripts, and Rants</description>
	<lastBuildDate>Wed, 12 May 2010 08:08:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery, PHP, and Forms</title>
		<link>http://notan00b.com/2009/09/jquery-php-and-forms/</link>
		<comments>http://notan00b.com/2009/09/jquery-php-and-forms/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 01:56:57 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[hidden]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=204</guid>
		<description><![CDATA[I decided to put up a quick post on how I have been using jQuery and PHP to process forms for me very easily.  To get started, let me give you a background on what I have been trying to do.  I have a page with a list of info, and I wanted [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to put up a quick post on how I have been using jQuery and PHP to process forms for me very easily.  To get started, let me give you a background on what I have been trying to do.  I have a page with a list of info, and I wanted to give the user the option of editing that info using jQuery&#8217;s built in dialog box because it is awesome looking.  There were a few ways to go about doing this, which is what I am going to describe.</p>
<h1>This is the goal!</h1>
<li>I click the link</li>
<li>A dialog box pops up</li>
<li>The text boxes have info filled in already</li>
<li>Something like this:<br />Name:<br />
<input type="text" value="Bob Jones"/></li>
<li>I can edit it, then submit it</li>
<li>I want the code to be small</li>
<p>The first way that I thought of was to create a form for every piece of info I pulled from the database.  So lets say for ID=1, there would be 1 form with all the info preloaded into it.  ID=2 would be a separate form with all different info.  This works, but I had to have about 20 dialog boxes per page, and it would cause the HTML output to be about 20 times larger than I needed.</p>
<p>In my head, I knew there had to be a way to do this with DHTML and jQuery, and I finally figured it out.  All I had to do was create a value and store it in the button that I was already using (well it was actually just a link).  So I turned <code>&lt;a href="#" class="editThis"&gt;Edit!&lt;/a&gt;</code> into <code>&lt;a href="#" class="editThis" id="1"&gt;Edit!&lt;/a&gt;</code>.  I used PHP to echo out the data already but now each link will have a different ID:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> class<span style="color: #000099; font-weight: bold;">\&quot;</span>editThis<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$row[UserId]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Edit!&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we have 20 links, each looking the same, but each with a unique ID.  This is where jQuery comes in handy.  We can look up the anchor by class, and then store the ID as a variable for later use!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.editThis&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> id<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we have the ID of the info we want to manipulate.  The next part was a little more difficult to figure out.  I want only 1 dialog box and 1 form, but want the info auto filled.  At first I was thinking we needed to do a lot of AJAX to pull out each and every variable that we want to edit, but then I figured out we could pass that info into HTML as a &#8220;HIDDEN&#8221; variable.  HTML is great because you can hide all sorts of stuff and the user will never see it.  I can set the style as &#8220;hidden&#8221;, or I can include it inside a tag somewhere, or better yet, and my favorite, I can create a hidden variable: <code>&lt;input type="hidden" id="editinfo1" value="myinfohere"&gt;</code>  Now we need to implement this into our PHP to write it to the HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>#<span style="color: #000099; font-weight: bold;">\&quot;</span> class<span style="color: #000099; font-weight: bold;">\&quot;</span>editThis<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$row[UserId]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Edit!&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>hidden<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; name=<span style="color: #000099; font-weight: bold;">\&quot;</span>editinfo<span style="color: #006699; font-weight: bold;">{$row['UserId']}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; id=<span style="color: #000099; font-weight: bold;">\&quot;</span>editinfo<span style="color: #006699; font-weight: bold;">{$row['UserId']}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; value=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$row[Name]</span>::<span style="color: #006699; font-weight: bold;">$row[Address]</span>::<span style="color: #006699; font-weight: bold;">$row[Age]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now our HTML will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot; class=&quot;editThis&quot; id=&quot;1&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;editinfo1&quot; id=&quot;editinfo1&quot; value=&quot;Bob Jones::123 N Street::26&quot;&gt;</pre></div></div>

<p>All our info is now conveniently stored for jQuery to access later!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.editThis&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> id<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> variables<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#editinfo&quot;</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> info<span style="color: #339933;">=</span>variables.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'::'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">+</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">+</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now for the fun part, using jQuery to dynamically change the values of our SINGLE form!<br />
Our form might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;dialog&quot; title=&quot;Edit User&quot;&gt;
    &lt;form method=&quot;post&quot; name=&quot;edituserform&quot; action=editUser.php&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;edituser&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;userid&quot; id=&quot;euid&quot; value=&quot;0&quot;&gt;
    &lt;center&gt;
        &lt;table width=&quot;75%&quot;&gt;
            &lt;tr&gt;
                &lt;td align=&quot;right&quot;&gt;User Name: &lt;/td&gt;
                &lt;td align=&quot;left&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;eusername&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align=&quot;right&quot;&gt;Address: &lt;/td&gt;
                &lt;td align=&quot;left&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;address&quot; id=&quot;eaddress&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align=&quot;right&quot;&gt;Age: &lt;/td&gt;
                &lt;td align=&quot;left&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;age&quot; id=&quot;eage&quot;&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/center&gt;
    &lt;/form&gt;
&lt;/div&gt;</pre></div></div>

<p>And our jQuery would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.editThis&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> id<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> variables<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#editinfo&quot;</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> info<span style="color: #339933;">=</span>variables.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'::'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eusername&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eaddress&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#eage&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;euid&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#dialog&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;open&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#dialog'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        autoOpen<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        width<span style="color: #339933;">:</span> <span style="color: #CC0000;">600</span><span style="color: #339933;">,</span>
        modal<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        position<span style="color: #339933;">:</span> <span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span>
        buttons<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">&quot;Update user&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                document.<span style="color: #660066;">edituserform</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
            <span style="color: #3366CC;">&quot;Cancel&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
                $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            <span style="color: #009900;">&#125;</span> 
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s it!  Hopefully it was easy to understand.  Let me know if you need anything cleared up a little!  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/09/jquery-php-and-forms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nifty PHP/AJAX tricks</title>
		<link>http://notan00b.com/2009/07/nifty-phpajax-tricks/</link>
		<comments>http://notan00b.com/2009/07/nifty-phpajax-tricks/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 21:03:52 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[evaluate]]></category>
		<category><![CDATA[exit]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=166</guid>
		<description><![CDATA[This brief tutorial covers usage of the exit function to help with AJAX scripts as well as how to return both a numeric and associative array via AJAX.]]></description>
			<content:encoded><![CDATA[<p>These are a couple awesome AJAX/PHP tricks I learned to make coding just slightly easier on myself.</p>
<h1>Exit</h1>
<p>Lets say we had an index page, and when the user click a button, it would display the time.  Typically, in the past I would have it go to another &#8220;remote procedure call&#8221; (RPC) page, like &#8220;time.php&#8221; where the main portion of the script would be &#8220;echo time();&#8221;.  This tends to clutter my folders with miscellaneous scripts if I have multiple AJAX events.  I may have a different RPC for every page, which could mean I have like 50 php files in one folder and I&#8217;m not sure which ones are the RPC and which ones are the main files.</p>
<p>I then started condensing them, making one large script for a few files, and using a $_POST['action'] to decide what to do.  So if I had an ajax.php page it might look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'hello'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;hello!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So now it will execute the portion of the script that it is told.  So if I point my AJAX to ajax.php and pass a post variable called &#8220;action=time&#8221;, it will return the time.  We have now condensed it slightly.</p>
<p>We can condense it even further by using the php function &#8220;exit();&#8221;.  This function completely stops (exits) the script.  If my script looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;hello &quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;world!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The output would look like this: <code>hello </code><br />
Exit will abort the script and not run anything after it.</p>
<p>Exit also has the capability to display (echo) a message as to why it is quitting, so you could essentially use exit() and let people know they aren&#8217;t logged in if you wanted.  Here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$notlogged</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>login.php<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Please log in to view this page&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'loggedin'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notlogged</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* Main Content Starts Here */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So if we had never logged into the site, all we would see is &#8220;Please log in to view this page&#8221; as a link that we could click.</p>
<p>Lets put this all together.  The exit function allows you to point the ajax script to the current page, as it will &#8220;exit&#8221; and echo the data you want without running the main content of the page over again.  Let me show you what I mean, using jQuery ajax, with a time.php.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//time.php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'g:i A'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'do'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'hello'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&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;AJAX Example&lt;/title&gt;
&lt;link type=&quot;text/css&quot; href=&quot;css/custom-theme/jquery-ui-1.7.2.custom.css&quot; rel=&quot;stylesheet&quot; /&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; src=&quot;js/jquery.geturlparams.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function() {
	$('#checktime').click(function(){
		$.get('time.php',
			{do:'time'},
			function(data){
				$('#timeorhello').html(data);
			});								 
	});
	$('#sayhello').click(function(){
		$.get('time.php',
			{do:'hello'},
			function(data){
				$('#timeorhello').html(data);
			});								 
	});
});
&lt;/script&gt;
&lt;body&gt;
&lt;div id=&quot;timeorhello&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;input type=&quot;button&quot; id=&quot;checktime&quot; value=&quot;Get Time&quot; /&gt;
&lt;input type=&quot;button&quot; id=&quot;sayhello&quot; value=&quot;Say Hello&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Pretty simple stuff right?  You can reduce the number of extra files by simply putting the AJAX commands at the top of the file.  If you put &#8220;echo(time());&#8221;, it would continue to run the entire page and mess up your AJAX.  This has made my life easier and my code a little more succinct.</p>
<h1>Arrays</h1>
<p>Because AJAX only accepts strings to be echo, and returned to the AJAX function, so a lot of people struggle with returning an array to Javascript through AJAX.  There are 2 ways to do this that don&#8217;t require JSON.</p>
<p>The first is simply to break the array up and make it into a string using the &#8220;implode&#8221; function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hello&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;world&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newarray</span><span style="color: #339933;">=</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;::&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$newarray</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>On the Javascript end, just split it up into an array again!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myArray<span style="color: #339933;">=</span>data.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'::'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That is by far the easiest way to return arrays.</p>
<p>There is one problem.  What if in PHP, your arrays didn&#8217;t have numerical keys, but strings: <code>$array['name']='bob'</code>.  This is where we run into a problem.  There is a way around this fairly easy.  Most languages have an &#8220;evaluate&#8221; command, which will take a string, and execute it as though it were code.  In PHP and Javascript, it is eval().  Here is a PHP example: <code>eval("echo 'Hello World!';");</code>.  This would output &#8220;Hello World!&#8221;.  In Javascript, it is exactly the same thing.  So lets use eval() to return a Javascript array!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'bob'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'age'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'96'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sex'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'male'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$return</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'var myArray={&quot;name&quot;:&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;, &quot;age&quot;:&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'age'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;, &quot;sex&quot;:&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sex'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;};
echo $return;
?&gt;</span></pre></div></div>

<p>And on the Javascript side, all you need to do is evaluate the string:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> handler<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>myArray<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Its a bit lengthy to do it this way, but will definitely get the job done.  One thing to watch out for would be quotes, plus signs, slashes, especially if the user gets to define some of the stuff that is being returned.</p>
<p>I hope this has helped out a little with using PHP and AJAX.  I spent hours trying to figure this stuff out the first time, but when I did, it made my life a lot simpler. </p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/nifty-phpajax-tricks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery tutorial has been posted.</title>
		<link>http://notan00b.com/2009/07/jquery-tutorial-has-been-posted/</link>
		<comments>http://notan00b.com/2009/07/jquery-tutorial-has-been-posted/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:54:03 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Post]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=143</guid>
		<description><![CDATA[This is a simple tutorial, designed mostly just to introduce you to jQuery.  If you have had some experience with Javascript, you should be able to pick this up very quickly after reading through the tutorial.  I provide the structure and a couple examples.  If anyone needs help with a script or [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple tutorial, designed mostly just to introduce you to jQuery.  If you have had some experience with Javascript, you should be able to pick this up very quickly after reading through the tutorial.  I provide the structure and a couple examples.  If anyone needs help with a script or is having problems getting it working, post a comment and I will help out as best I can.  <a href="/tutorials/">Check out the page!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/jquery-tutorial-has-been-posted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery &#8211; Lesson 2</title>
		<link>http://notan00b.com/2009/07/jquery-lesson-2/</link>
		<comments>http://notan00b.com/2009/07/jquery-lesson-2/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 00:05:25 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[click]]></category>
		<category><![CDATA[each]]></category>
		<category><![CDATA[hover]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sibling]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=125</guid>
		<description><![CDATA[I have been working pretty intensely with jQuery and have learned a lot.  It is a difficult language to work with because it is picky.  But once you understand it, it is actually quite simple to manipulate.
Today I want to cover parent/child/sibling relationships and how jQuery can be very effective here.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working pretty intensely with jQuery and have learned a lot.  It is a difficult language to work with because it is picky.  But once you understand it, it is actually quite simple to manipulate.</p>
<p>Today I want to cover parent/child/sibling relationships and how jQuery can be very effective here.  I spent a while trying to figure this out in javascript, and yes, it is completely do-able in just a little more code, but jQuery always has the UI plugins that make coding super easy.  Let me show you some code I currently have:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
   <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#rows'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
         <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rows-add-class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
         <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rows-add-class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.section2, .section3, .section4, .section5'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;viewClient.php?id=&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.section1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">else</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cb'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I know this looks complicated, but lets break it down line by line.</p>
<ol>
<li><code>$('div').each(function (){</code></li>
<p>This code goes through each &lt;div&gt; in my code, and with each &lt;div&gt; it finds, it executes a function, which is the remainder of the code.</p>
<li><code>if($(this).is('#rows')) {</code></li>
<p>So when it finds a
<div>, it checks to see if the &lt;div&gt; that was found &#8220;is&#8221; (or has the property of) &#8216;#rows&#8217;.  The # in the front means the &lt;div&gt; id.  If there is a &#8220;.&#8221; in front, it means the &lt;div&gt; class.  If there is nothing, then it means that it is a tag itself.  So when it finds the div tag with the id=&#8221;rows&#8221;, it will execute the following code.</p>
<li><code>$(this).hover(</code></li>
<p>Simply, it adds a hover class to the div with the id=&#8221;rows&#8221;.  When you add a hover, you need to have it do 2 things, mouseover and mouseout.  So the next parts of the code describe mouseover and mouseout respectively.</p>
<li><code>function() { $(this).addClass('rows-add-class'); },</code></li>
<p>So on mouseover, it will execute this function, which is, it will add a class called &#8216;rows-add-class&#8217; to the div we have selected.  Note the &#8220;,&#8221; at the end, which means that this is the next line is also part of hover().</p>
<li><code>function() { $(this).removeClass('rows-add-class'); }</code></li>
<p>On mouseout, it will remove the class.  We could have it add another class or give us an alert if we wanted, but typically when you hover over something with the mouse, you want to emphasize/change something, and when you move it out, you want it to return to normal.</p>
<li><code>);</code></li>
<p>So finally we start closing stuff up.  This closes up the hover statement.</p>
<li><code>$(this).children('.section2, .section3, .section4, .section5').click(function(){</code></li>
<p>Here we are getting into children.  If you have a div, and inside that div, you have multiple other divs, you may want to do something to those divs.  What I am doing here is adding an &#8220;onclick&#8221; function to the children divs with classes &#8220;section2&#8243;, &#8220;section3&#8243;, &#8220;section4&#8243;, &#8220;section5&#8243;.  Notice how here I used &#8216;.section1, etc&#8217;, the &#8220;.&#8221; signifies classes.  So this is statement, I am adding an &#8220;onclick&#8221; to the child tags under &#038;ltldiv id=&#8221;rows&#8221;&gt;.  The next line will tell me what exactly I am going to do when I click on one of those 4 child divs.</p>
<li><code>window.location.href= "viewClient.php?id="+$(this).siblings('.small').children('#cb').val();</code></li>
<p>Wow, thats a long line of code!  window.location.href= is a redirect, so basically, when you click the divs, it will act like a link and take you somewhere else.  It looks like it will take you to a viewClient.php page with the id= whatever $(this).siblings(&#8216;.small&#8217;).children(&#8216;#cb&#8217;).val(); equals.  It gets a little confusing here.  So &lt;div id=&#8221;rows&#8221;&gt; is set up with a few children tags, and those children have a few tags.  All of the children are siblings.  So if I was to click on one of the children, say one with the class &#8220;section2&#8243;, I want to find out info about his sibling, with the class &#8220;small&#8221;.  Now &#8220;small&#8221; has a child with the id=&#8221;cb&#8221;.  Cb stands for check box.  Basically, when you click on the div, it will find its sibling&#8217;s, child&#8217;s value, which is the ID # we are looking for.  At the bottom of the page you can see the layout of the div with children and grandchildren.  So to recap, this line redirects us to &#8220;viewClient.php?id=1&#8243;.<br />
Why did I do this?  Well I am pulling data out of a database, and I don&#8217;t want to make a link in every div so they have to click on the words to be redirected.  These couple lines of code make it much easier for the user to redirect to the page they want.</p>
<li><code>});</code></li>
<p>Just closing up the &#8220;onclick&#8221; that we added to those 4 divs.</p>
<li><code>$(this).children('.section1').click(function(){</code></li>
<p>Here is the div with class=&#8221;section1&#8243; and we are adding a different &#8220;onclick&#8221; function to it.  Let&#8217;s see what we want it to do.</p>
<li><code>if($(this).siblings('.small').children('#cb').attr('checked'))</code></li>
<p>This looks similar to line 8 where we locate the sibling with the class=&#8221;small&#8221; and the child it has with the id=&#8221;cb&#8221;.  So we are locating our checkbox.  If our checkbox is checked (.attr(&#8216;checked&#8217;) returns true if checked, false if not checked), we are going to do something.  That was pretty easy now that siblings and children make a little sense.</p>
<li><code>$(this).siblings('.small').children('#cb').attr('checked',false);</code></li>
<p>Ok, so if it was checked, all this will do is set &#8216;checked&#8217; to false, meaning it will un-check the check box.  </p>
<li><code>else</code></li>
<p>If it wasn&#8217;t checked, then what.</p>
<li><code>$(this).siblings('.small').children('#cb').attr('checked',true);</code></li>
<p>Well then, check it!  So why did I add this code?  Well just to add it really.  It makes clicking the check box slightly easier.  They can click on this div, and it will check/uncheck the checkbox for them.
</ol>
<p>The rest of the code simply closes up the function that I created.  This is something I would have it do on start up, rather than allowing the user to click a button to enable these features.</p>
<p>This is the HTML markup that was used in the code.  The classes are easily created and is something you can do on your own.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;rows&quot;&gt;
   &lt;div class=&quot;small&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;cb&quot; value=&quot;1&quot;&gt;&lt;/div&gt;
   &lt;div class=&quot;section1&quot;&gt;1 (Clients ID)&lt;/div&gt;
   &lt;div class=&quot;section2&quot;&gt;Bob (Clients Name)&lt;/div&gt;
   &lt;div class=&quot;section3&quot;&gt;123 Fast Lane (Clients Address)&lt;/div&gt;
   &lt;div class=&quot;section4&quot;&gt;12345 (Clients Zip)&lt;/div&gt;
   &lt;div class=&quot;section5&quot;&gt;(123)555-1212 (Clients Phone)&lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Pretty simple layout causes pretty intense code.  Hopefully my explanation shows you some of what jQuery can do for you and provides a plan of attack for you.  If you want any help, let me know and I will be willing to explain something, review your code, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/jquery-lesson-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQueryui drop down menu</title>
		<link>http://notan00b.com/2009/07/jqueryui-drop-down-menu/</link>
		<comments>http://notan00b.com/2009/07/jqueryui-drop-down-menu/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 01:26:22 +0000</pubDate>
		<dc:creator>pyr0t3chnician</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[animated]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[down]]></category>
		<category><![CDATA[drop]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jqueryui]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://notan00b.com/?p=114</guid>
		<description><![CDATA[I was going to title this post: &#8220;jQuery, your friend and enemy&#8221; because I spent close to 2 hours today hating it and thinking of coding my own functions rather than trying to work with it.  Eventually I figured out what I was doing and made it work beautifully with the custom ui template [...]]]></description>
			<content:encoded><![CDATA[<p>I was going to title this post: &#8220;jQuery, your friend and enemy&#8221; because I spent close to 2 hours today hating it and thinking of coding my own functions rather than trying to work with it.  Eventually I figured out what I was doing and made it work beautifully with the <a href="http://jqueryui.com/themeroller/">custom ui template I made at their website</a>.  Because I learned it, I figured I would share it.</p>
<p>The menu is very simple, and very customizable.  Because I am using a jQuery theme/template, you may have to tweak yours a little to take out the icons.  First the jQuery code in the header:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul#icons li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-state-hover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-state-hover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#menu'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul#icons'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul#icons'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>For jQuery n00bs, there are 2 things done here when the page loads.  The first is it adds a hover class to my links (which I chose to do as a list).  With a little editing, you could make it add a cover class to anything you want.  Secondly, I add another hover function to the tag with the id &#8220;menu&#8221;.  This one will show the list with the id=&#8221;icons&#8221; when I hover over it, and take it away when I move my mouse away.  Not to mention, it is animated slightly, so it drops down, which is something that would take a hell of a lot more lines than just 3-4 to do.</p>
<p>Now for a little css to make our menu fantabulous and have it stuck at the top of the page:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
ul<span style="color: #cc00cc;">#icons</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul<span style="color: #cc00cc;">#icons</span> li <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul<span style="color: #cc00cc;">#icons</span> span<span style="color: #6666ff;">.ui-icon</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.menulinks<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Like I said, I use a template that has multiple icons to chose from, and I use those in my menu.  You guys can use whatever, but it will require some editing.</p>
<p>Finally, the HTML code with my links:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;menulinks ui-corner-all ui-widget-content&quot; id=&quot;menu&quot;&gt;
&lt;div style=&quot;text-align:center;border-bottom:solid 1px #CCC;&quot; class=&quot;ui-widget&quot;&gt;&lt;h2 style=&quot;margin:1px;&quot;&gt;Menu&lt;/h2&gt;&lt;/div&gt;
&lt;ul id=&quot;icons&quot; class=&quot;ui-widget ui-helper-clearfix&quot;&gt;
&lt;a href=&quot;index.php&quot;&gt;&lt;li class=&quot;ui-state-default ui-corner-all&quot;&gt;&lt;span class=&quot;ui-icon ui-icon-circle-triangle-e&quot;&gt;&lt;/span&gt;Home&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;manageClients.php&quot;&gt;&lt;li class=&quot;ui-state-default ui-corner-all&quot;&gt;&lt;span class=&quot;ui-icon ui-icon-circle-triangle-e&quot;&gt;&lt;/span&gt;View Orders&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;manageTickets.php&quot;&gt;&lt;li class=&quot;ui-state-default ui-corner-all&quot;&gt;&lt;span class=&quot;ui-icon ui-icon-circle-triangle-e&quot;&gt;&lt;/span&gt;View Tickets&lt;/li&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;/div&gt;</pre></div></div>

<p>And once again I will say it, if you don&#8217;t have the template downloaded, it won&#8217;t work unless you edit some stuff.  You can make a very basic one with just text very simply, but this is a nicer looking one cause I used a template.</p>
<p>If you want the stripped down, basic code, here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&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;EPCO - Order Form&lt;/title&gt;
&lt;link type=&quot;text/css&quot; href=&quot;css/custom-theme/jquery-ui-1.7.2.custom.css&quot; rel=&quot;stylesheet&quot; /&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;
$(document).ready(function(){
	$('#menu').hover(
		function() { $('ul#list').show('fast'); }, 
		function() { $('ul#list').hide('fast'); }
	);
});
&nbsp;
&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
.menulinks{
	position:absolute;
	left:5px;
	top:5px;
	z-index:2;
	width:150px;
	padding:10px;
}
&lt;/style&gt;	
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;menu&quot; class=&quot;menulinks&quot;&gt;
&lt;div&gt;&lt;h2&gt;Menu&lt;/h2&gt;&lt;/div&gt;
&lt;ul id=&quot;list&quot;&gt;
&lt;a href=&quot;index.php&quot;&gt;&lt;li&gt;Home&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;manageClients.php&quot;&gt;&lt;li&gt;View Orders&lt;/li&gt;&lt;/a&gt;
&lt;a href=&quot;manageTickets.php&quot;&gt;&lt;li&gt;View Tickets&lt;/li&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Thats it!  Good luck.  I will post more jQuery tutorials as I figure stuff out.</p>
]]></content:encoded>
			<wfw:commentRss>http://notan00b.com/2009/07/jqueryui-drop-down-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
