<?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>Webdevelopment at huuah.com &#187; jQuery</title>
	<atom:link href="http://huuah.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://huuah.com</link>
	<description>webdevelopment, cms, php, javascript etc</description>
	<lastBuildDate>Sat, 04 Sep 2010 22:55:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Basic jQuery div rotator</title>
		<link>http://huuah.com/basic-jquery-div-rotator/</link>
		<comments>http://huuah.com/basic-jquery-div-rotator/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 21:54:24 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=536</guid>
		<description><![CDATA[<p>So &#8211; how do one make a simple rotations function in jquery? There are many ways to do this, so I will just demonstrate one of them here:</p>
<a name="Example+code+for+the+jQuery+DIV+rotator%3A"></a>Example code for the jQuery DIV rotator:
<pre class="brush: xml;">
&#60;div class=&#34;&#34;&#62;
&#60;div class=&#34;focusitem active&#34;&#62;Item 1&#60;/div&#62;
&#60;div class=&#34;focusitem notactive&#34;&#62;Item 2&#60;/div&#62;
&#60;div</pre><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>So &#8211; how do one make a simple rotations function in jquery? There are many ways to do this, so I will just demonstrate one of them here:</p>
<a name="Example+code+for+the+jQuery+DIV+rotator%3A"></a><h1>Example code for the jQuery DIV rotator:</h1>
<pre class="brush: xml;">
&lt;div class=&quot;&quot;&gt;
&lt;div class=&quot;focusitem active&quot;&gt;Item 1&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 2&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 3&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 4&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>And this will output 4 divs as shown here:</p>
<div class="focusitem&nbsp;active">Item 1</div>
<div class="focusitem&nbsp;notactive">Item 2</div>
<div class="focusitem&nbsp;notactive">Item 3</div>
<div class="focusitem&nbsp;notactive">Item 4</div>
<p>Nothing exciting about this, really. So &#8211; lets add the forward and backward button for the shifting of visible divs.</p>
<a name="Make+the+items+rotate"></a><h1>Make the items rotate</h1>
<pre class="brush: xml;">
&lt;div class=&quot;goleft&quot;&gt;Go Left&lt;/div&gt;

&lt;div class=&quot;&quot;&gt;
&lt;div class=&quot;focusitem active&quot;&gt;Item 1&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 2&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 3&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 4&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;goright&quot;&gt;Go Right&lt;/div&gt;
</pre>
<p>There is now added 2 buttons/divs/textsfield &#8211; a left one and a right one. All we have to do, is make the buttons change which div is visible. The easy way to do this, is by changing the class name of the div and with CSS control the visibility and format.</p>
<p>To register a click event on the left and right buttons, we have to use the click()-function in jQuery.</p>
<p>That can look like this:</p>
<p>Javascript:</p>
<pre class="brush: jscript;">
     // trigger the mouse click even
     $(&quot;.goleft&quot;).click( function(e) {
        // get the current active element
        var $active = $(&quot;.active&quot;);
        // get the previous element or, if no previous then get the last item in the focusitem-class.
        var $next = $active.prev().length ? $active.prev() : $(&quot;.focusitem:last&quot;);

        // set the visibility of the active and notactive classes.
        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });
</pre>
<p>CSS:</p>
<pre class="brush: css;">
&lt;div class=&quot;focusitem active&quot;&gt;Item 1&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 2&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 3&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 4&lt;/div&gt;
</pre>
<a name="Result%3A"></a><h1>Result:</h1>
<div class="goleft">Go Left</div>
<div class="">
<div class="focusitem active">Item 1</div>
<div class="focusitem notactive">Item 2</div>
<div class="focusitem notactive">Item 3</div>
<div class="focusitem notactive">Item 4</div>
</div>
<div class="goright">Go Right</div>
<div class="clear"></div>
<a name="How+it+works"></a><h1>How it works</h1>
<p>The jQuery rotation code gets activated as soon as a user clicks the buttons. It find the active element, and the next or previous element corresponding to which buttons is activated and the toggles the active and notactive classes on the focusitems.</p>
<p>Complete jQuery code:</p>
<pre class="brush: jscript;">
(document).ready(function() {

    $(&quot;.goleft&quot;).click( function(e) {
        var $active = $(&quot;.active&quot;);
        var $next = $active.prev().length ? $active.prev() : $(&quot;.focusitem:last&quot;);

        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });

    $(&quot;.goright&quot;).click( function(e) {
        var $active = $(&quot;.active&quot;);
        var $next = $active.next().length ? $active.next() : $(&quot;.focusitem:first&quot;);

        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });

});
</pre>
<p>Complete CSS for the above example:</p>
<pre class="brush: css;">
.active {
    display: block;
    width: 100px;
    float: left;
}
.notactive {
    display: none;
}

.goleft, .goright {
    cursor: pointer;
    width: 100px;
    float: left;
    border: 1px solid;
}
</pre>
<a name="Now+what%3F"></a><h1>Now what?</h1>
<p>For more fancy display that my example shows, try putting some images ind the focusitem and make some nice arrows for the go left and right buttons. The usability of the rotator will improve a lot, by making some easy layout adjustments. </p>
<p>Obvious expansions for this kind of rotator would be a more fancy shift/glide between active divs or perhaps loading each element with Ajax, but this is intensionally not covered in this post. </p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/basic-jquery-div-rotator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting position from jQuery UI sortable</title>
		<link>http://huuah.com/getting-position-from-jquery-ui-sortable/</link>
		<comments>http://huuah.com/getting-position-from-jquery-ui-sortable/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 11:07:43 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=461</guid>
		<description><![CDATA[<p>The jQuery UI sortable widget offers a great interface for listing and moving element around. </p>
<p>I have been working on a small project of mine and figured that the sortable widget could be a great feature. I then started to output the list and the element that should be&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>The jQuery UI sortable widget offers a great interface for listing and moving element around. </p>
<p>I have been working on a small project of mine and figured that the sortable widget could be a great feature. I then started to output the list and the element that should be draggable like this:</p>
<p>My HTML list</p>
<pre class="brush: xml;">
&lt;ul id=&quot;sort1&quot;&gt;
  &lt;li&gt;
    &lt;div&gt;box no 1&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;div&gt;box no 2&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;div&gt;box no 3&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>My jQuery code to enable the sortable widget and for getting a serialized result when an element has been dragged around:</p>
<pre class="brush: jscript;">
$(document).ready(function() {
    $(&quot;#sort1&quot;).sortable({
        opacity: 0.6,
        update: function(event, ui) {
            var info = $(this).sortable(&quot;serialize&quot;);
            $(&quot;#sort1output&quot;).html(info);
        }

    });
});
</pre>
<p>Example (try dragging a box up or down):</p>
<ul id="sort1">
<li>
<div>box no 1</div>
</li>
<li>
<div>box no 2</div>
</li>
<li>
<div>box no 3</div>
</li>
</ul>
<p>Serialized output (updated when a box is dragged):<span id="sort1output"><strong>Output will be shown here</strong></span></p>
<p>So. Nothing. No output what so ever.</p>
<p>I have spend several hour researching this problem, because the documentation on jqueryui.com lists that the serialize and toArray events should return output.</p>
<p>And then. Finaly. I stumpled upon a note regarding the id name of the element that gets dragged. I have seen no documentation about this and was quite puzzled. I digged some more into this id-hint and realized that the element that gets moved around, has to have a unique id tag ending with a number like this: &#8220;element_2&#8243;.</p>
<p>The working code will then be:</p>
<pre class="brush: xml; highlight: [2,5,8];">
&lt;ul id=&quot;sort2&quot;&gt;
  &lt;li id=&quot;element_1&quot;&gt;
    &lt;div&gt;box no 1&lt;/div&gt;
  &lt;/li&gt;
  &lt;li id=&quot;element_2&quot;&gt;
    &lt;div&gt;box no 2&lt;/div&gt;
  &lt;/li&gt;
  &lt;li id=&quot;element_3&quot;&gt;
    &lt;div&gt;box no 3&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<ul id="sort2">
<li id="element_1">
<div>box no 1</div>
</li>
<li id="element_2">
<div>box no 2</div>
</li>
<li id="element_3">
<div>box no 3</div>
</li>
</ul>
<p>Serialized output (updated when a box is dragged):<span id="sort2output" style="font-weight: bold"><strong>Output will be shown here</strong></span></p>
<p>I hope this tip is helpfull.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/getting-position-from-jquery-ui-sortable/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jQuery and dropdown / select boxes</title>
		<link>http://huuah.com/jquery-and-dropdown-select-boxes/</link>
		<comments>http://huuah.com/jquery-and-dropdown-select-boxes/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 10:54:39 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=434</guid>
		<description><![CDATA[<p>With jQuery it is quick and easy to access and modify elements in a select dropdown box. There are of course several ways of doing thing and I will try to cover most of them here.</p>
<p>Quicklinks:<br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#testsetup">The test setup</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#getthevalue">Get the selected value from the select /</a>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>With jQuery it is quick and easy to access and modify elements in a select dropdown box. There are of course several ways of doing thing and I will try to cover most of them here.</p>
<p>Quicklinks:<br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#testsetup">The test setup</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#getthevalue">Get the selected value from the select / dropdown box</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#setthevalue">Set the selected value</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#insertvalue">Insert new options and values in the dropdown box</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#removevalue">Removing an entry from the select box</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#enabledisable">Disable and enable options</a><br />
<a href="http://huuah.com/jquery-and-dropdown-select-boxes/#thecode">The code</a></p>
<p><a name="testsetup"></a></p>
<a name="The+test+setup."></a><h1>The test setup.</h1>
<p>For the following examples I will use a dropdown / select box like this:</p>
<select id="dropdowntestsetup">
<option value="apples">10 Apples</option>
<option value="oranges">5 Oranges</option>
<option value="bananas">12 Bananes</option>
</select>
<p>The HTML-code for the dropdown is where basic:</p>
<pre class="brush: xml;">
&lt;select id=&quot;dropdown&quot;&gt;
&lt;option value=&quot;apples&quot;&gt;10 Apples&lt;/option&gt;
&lt;option value=&quot;oranges&quot;&gt;5 Oranges&lt;/option&gt;
&lt;option value=&quot;bananas&quot;&gt;12 Bananes&lt;/option&gt;
&lt;/select&gt;
</pre>
<p><a name="getthevalue"></a></p>
<a name="Get+the+selected+value+from+the+select+%2F+dropdown+box."></a><h1>Get the selected value from the select / dropdown box.</h1>
<p>When a value is selected, it could be nice to use the value for something and the first step to doing this, is to receive the value. This is actually very simple to do:<br />
<strong>dropdown1</strong>:<br />
<select id="dropdown1">
<option value="apples">10 Apples</option>
<option value="oranges">5 Oranges</option>
<option value="bananas">12 Bananes</option>
</select>
<p><strong>button1</strong>: <button id="button1">Fetch value from dropdown</button></p>
<p>Code:</p>
<pre class="brush: jscript;">
    $(&quot;#button1&quot;).click( function() {
        alert(&quot;The selected value is: &quot; + $(&quot;#dropdown1&quot;).val() );
    });
</pre>
<p>Here I have used the val()-function on the dropdown box the receive the value for the selected element and it will output the content of the &#8220;value&#8221;-parameter on the select-box.</p>
<p>If you would rather have the visible text (ie. 10 Apples or 5 Oranges) outputted, you will have to use the html()-function instead. It&#8217;s a bit more tricky, as you should only get the content of the selected value and not the entire select-box.<br />
To do this, we have to do a combination like this:<br />
<strong>button2</strong>: <button id="button2">Fetch content from dropdown</button></p>
<p>Code:</p>
<pre class="brush: jscript;">
    $(&quot;#button2&quot;).click( function() {
        var selectedvalue = $(&quot;#dropdown1&quot;).val();
        alert(&quot;The selected value is: &quot; + $(&quot;#dropdown1 option[value=&quot;+selectedvalue+&quot;]&quot;).html() );
    });
</pre>
<p>Another and more simple way of getting the text from the selected element could be:</p>
<pre class="brush: jscript;">
    $('#dropdown1 :selected').text();
</pre>
<p><a name="setthevalue"></a></p>
<a name="Set+the+selected+value."></a><h1>Set the selected value.</h1>
<p>Setting the selected value is very easy. All you have to do, is use the val()-function:<br />
<strong>dropdown2</strong>:<br />
<select id="dropdown2">
<option value="apples">10 Apples</option>
<option value="oranges">5 Oranges</option>
<option value="bananas">12 Bananes</option>
</select>
<p><strong>button3</strong>: <button id="button3">Select &#8216;oranges&#8217;</button><br />
<strong>button4</strong>: <button id="button4">Select &#8216;bananas&#8217;</button></p>
<p>code:</p>
<pre class="brush: jscript;">
    $(&quot;#button3&quot;).click( function() {
        $(&quot;#dropdown2&quot;).val(&quot;oranges&quot;);
    });
    $(&quot;#button4&quot;).click( function() {
        $(&quot;#dropdown2&quot;).val(&quot;bananas&quot;);
    });
</pre>
<p><a name="insertvalue"></a></p>
<a name="Insert+new+options+and+values+in+the+dropdown+box."></a><h1>Insert new options and values in the dropdown box.</h1>
<p>If the content of the dropdown are depending on other fields, it is often necessary to change or insert new values to a dropdown box.<br />
This can be done by appending new &lt;option&gt;-tags to the &lt;select&gt;-box:<br />
<strong>dropdown3</strong>:<br />
<select id="dropdown3">
<option value="apples">10 Apples</option>
<option value="oranges">5 Oranges</option>
<option value="bananas">12 Bananes</option>
</select>
<p><strong>button5</strong>: <button id="button5">Append a new field named &#8217;20 Grapes&#8217;</button><br />
<strong>button6</strong>: <button id="button6">Prepend a new field named &#8217;20 Melons&#8217;</button></p>
<p>Code:</p>
<pre class="brush: jscript;">
    $(&quot;#button5&quot;).click( function() {
        // insert new option at the bottom of the dropdown box
        $(&quot;#dropdown3&quot;).append('&lt;option selected=selected value=&quot;grapes&quot;&gt;20 Grapes&lt;/option&gt;');
    });
    $(&quot;#button6&quot;).click( function() {
        // insert new option at the top of the dropdown box
        $(&quot;#dropdown3&quot;).prepend('&lt;option selected=selected value=&quot;melons&quot;&gt;20 Melons&lt;/option&gt;');
    });
</pre>
<p><a name="removevalue"></a></p>
<a name="Removing+an+entry+from+the+select+box."></a><h1>Removing an entry from the select box.</h1>
<p>Remove options is very easy. All you need is knowing which values to remove:<br />
<strong>dropdown4</strong>:<br />
<select id="dropdown4">
<option value="apples">10 Apples</option>
<option value="oranges">5 Oranges</option>
<option value="bananas">12 Bananes</option>
</select>
<p><strong>button7</strong>: <button id="button7">Remove the &#8220;10 Apples&#8221; option</button></p>
<p>Code:</p>
<pre class="brush: jscript;">
    $(&quot;#button7&quot;).click( function() {
        $(&quot;#dropdown4 option[value='apples']&quot;).remove();
    });
</pre>
<p><a name="enabledisable"></a></p>
<a name="Disable+and+enable+options."></a><h1>Disable and enable options.</h1>
<p>If some of the options in the dropdown is depending on other values, it is sometimes nice to enable and disable entries on the fly.<br />
<strong>dropdown5</strong>:<br />
<select id="dropdown5">
<option value="apples">10 Apples</option>
<option value="oranges">5 Oranges</option>
<option value="bananas">12 Bananes</option>
</select>
<p><strong>button8</strong>: <button id="button8">Disable the&#8221;5 Oranges&#8221; option</button><br />
<strong>button9</strong>: <button id="button9">Enable the &#8220;5 Oranges&#8221; option</button></p>
<p>Code:</p>
<pre class="brush: jscript;">
    $(&quot;#button8&quot;).click( function() {
        $(&quot;#dropdown5 option[value='oranges']&quot;).attr(&quot;disabled&quot;, &quot;disabled&quot;);
    });

    $(&quot;#button9&quot;).click( function() {
        $(&quot;#dropdown5 option[value='oranges']&quot;).removeAttr(&quot;disabled&quot;);
    });
</pre>
<p><a name="thecode"></a></p>
<a name="The+code."></a><h1>The code.</h1>
<p>The complete jQuery code with the above examples, can be <a href="/js/dropdown.js">downloaded here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/jquery-and-dropdown-select-boxes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery, accessing and modifying form elements</title>
		<link>http://huuah.com/jquery-accessing-and-modifying-form-elements/</link>
		<comments>http://huuah.com/jquery-accessing-and-modifying-form-elements/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 20:43:58 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[elements]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=333</guid>
		<description><![CDATA[<p>When working with HTML Forms, it can in some situations improve the usability of the site, if the content of elements can change and reflect the options, that the visitor made in the previous fields.</p>
<p>The most common form element are input, checkbox, radio buttons, textarea and dropdown boxes and&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>When working with HTML Forms, it can in some situations improve the usability of the site, if the content of elements can change and reflect the options, that the visitor made in the previous fields.</p>
<p>The most common form element are input, checkbox, radio buttons, textarea and dropdown boxes and I will try to cover them all, even though the code might be the same or very much alike.</p>
<a name="Input+boxes"></a><h1>Input boxes</h1>
<input type="text" size="30" value="input box demo text" name="inputbox" id="inputbox" />
</p>
<p><em>Fetching content is done with</em>:</p>
<pre class="brush: jscript;">
// fetching the value
$(&quot;#inputbox&quot;).val();
</pre>
<p>Try it:<br />
<button id="inputboxbtn1">Make a popup with the contents</button></p>
<p><em>Setting new content is done with</em>:</p>
<pre class="brush: jscript;">
// setting a new value
$(&quot;#inputbox&quot;).val(&quot;We have now changed the text&quot;);
</pre>
<p>Try it:<br />
<button id="inputboxbtn2">Change the content to &#8220;We have now changed the text&#8221;</button></p>
<a name="Check+boxes+%2F+Radio+boxes"></a><h1>Check boxes / Radio boxes</h1>
<p>Both check boxes and radio boxes works the same way.</p>
<table id="elementID">
<tr>
<td>Field 1</td>
<td>
<input type="checkbox" value="Field 1" name="checkbox"></td>
</tr>
<tr>
<td>Field 2</td>
<td>
<input type="checkbox" value="Field 2" name="checkbox"></td>
</tr>
<tr>
<td>Field 3</td>
<td>
<input type="checkbox" value="Field 3" name="checkbox"></td>
</tr>
</table>
<p><em>Checking all fields:</em></p>
<pre class="brush: jscript;">
// loop through each checkfield
$(&quot;#elementID input:checkbox&quot;).each( function() {
  // set checked=checked
  $(this).attr(&quot;checked&quot;, &quot;checked&quot;);
});
</pre>
<p>Try it:<br />
<button id="checkboxbtn1">Check all boxes</button></p>
<pre class="brush: jscript;">
// loop through each checkfield
$(&quot;#elementID input:checkbox&quot;).each( function() {
  // if field is checked, then uncheck or the other way around
  this.checked ? $(this).attr(&quot;checked&quot;, &quot;&quot;) : $(this).attr(&quot;checked&quot;, &quot;checked&quot;);
});
</pre>
<p><button id="checkboxbtn2">Toggle boxes</button></p>
<p><em>Outputting the checked status for each field:</em></p>
<pre class="brush: jscript;">
// temporary variable for output purposes
var status = &quot;&quot;;
// loop through each fieldfield
$(&quot;#elementID input:checkbox&quot;).each( function() {
  // save field value and checkstate in variable
  status += $(this).val() + &quot; is &quot; + this.checked + &quot;,  &quot;;
});
// make a popup box with the result
alert(status);
</pre>
<p>Try it:<br />
<button id="checkboxbtn3">Output checkbox status</button></p>
<a name="Textarea"></a><h1>Textarea</h1>
<p><textarea id="textarea">Textarea sample text</textarea><br />
<em>Fetching content is done with</em>:</p>
<pre class="brush: jscript;">
// fetching the value
$(&quot;#textarea&quot;).html();
</pre>
<p>Try it:<br />
<button id="textareabtn1">Make a popup with the contents</button></p>
<p><em>Setting new content is done with</em>:</p>
<pre class="brush: jscript;">
// setting a new value
$(&quot;#textarea&quot;).html(&quot;We have now changed the text&quot;);
</pre>
<p>Try it:<br />
<button id="textareabtn2">Change the content to &#8220;We have now changed the text&#8221;</button></p>
<a name="Dropdown+boxes"></a><h1>Dropdown boxes</h1>
<select id="selectbox">
<option value="select1">Select 1</optoin></p>
<option value="select2">Select 2</optoin></p>
<option value="select3">Select 3</optoin><br />
</select>
<p><em>Fetch the value if the dropdown box:</em></p>
<pre class="brush: jscript;">
$(&quot;#selectbox&quot;).val()
</pre>
<p>Try it:<br />
<button id="selectboxbtn1">Output which option is selected</button></p>
<p><em>Selecting option 2 in the downdown box:</em></p>
<pre class="brush: jscript;">
// loop through options
$(&quot;#selectbox option&quot;).each( function() {
  // if the value is equal to 'select2', then select it
  if ($(this).val() == &quot;select2&quot;) {
    $(this).attr(&quot;selected&quot;, &quot;selected&quot;);
  }
});
</pre>
<p>Try it:<br />
<button id="selectboxbtn2">Select option 2</button></p>
<p><em>Selecting option 3 in the downdown box:</em></p>
<pre class="brush: jscript;">
// loop through options
$(&quot;#selectbox option&quot;).each( function() {
  // if the value is equal to 'select3', then select it
  if ($(this).val() == &quot;select3&quot;) {
    $(this).attr(&quot;selected&quot;, &quot;selected&quot;);
  }
});
</pre>
<p>Try it:<br />
<button id="selectboxbtn3">Select option 3</button></p>
<p>There you go. A small demonstration of how to access form elements. There above examples is just one way of doing it. There are other ways as well.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/jquery-accessing-and-modifying-form-elements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Howto make a jQuery menu plugin</title>
		<link>http://huuah.com/howto-make-a-jquery-menu-plugin/</link>
		<comments>http://huuah.com/howto-make-a-jquery-menu-plugin/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 10:10:58 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=295</guid>
		<description><![CDATA[<p>If you want to reuse your jQuery code, it can be a good idea to make the code into a jQuery Plugin. This makes it easier to use on different elements or even to distribute it.</p>
<p><strong>Demonstration:</strong><br />
I have made a small simple 1 level menu for this demonstration. If&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>If you want to reuse your jQuery code, it can be a good idea to make the code into a jQuery Plugin. This makes it easier to use on different elements or even to distribute it.</p>
<p><strong>Demonstration:</strong><br />
I have made a small simple 1 level menu for this demonstration. If you hover you mouse on Menu 1 or Menu 3 you will see a submenu sliding down. Menu 2 has no submenu and will therefor display nothing.</p>
<div style="clear: both; height: 60px;">
<ul id="nav">
<li><a href="#">Menu 1</a>
<ul>
<li><a href="#">Menu 1.1</a></li>
<li><a href="#">Menu 1.2</a></li>
<li><a href="#">Menu 1.3</a></li>
</ul>
</li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a>
<ul>
<li><a href="#">Menu 3.1</a></li>
<li><a href="#">Menu 3.2</a></li>
<li><a href="#">Menu 3.3</a></li>
</ul>
</li>
</ul>
</div>
<p><strong>How: The HTML</strong><br />
The HTML is pretty much a standard list like this:</p>
<pre class="brush: xml;">
&lt;ul id=&quot;nav&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 1&lt;/a&gt;
        &lt;ul&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 1.1&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 1.2&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 1.3&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 2&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 3&lt;/a&gt;
        &lt;ul&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 3.1&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 3.2&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Menu 3.3&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p><strong>How: The basic of a plugin</strong><br />
The very basic setup for a jQuery Plugin is the following couple of lines, where I am creating a function called menu(), which can be called on an element.:</p>
<pre class="brush: jscript;">
(function($) {
    $.fn.menu = function() {
        ... javascript code goes here...
    }
})(jQuery);
</pre>
<p>To activate the plugin, you will have to call the menu() function on an element, which can be done like this:</p>
<pre class="brush: jscript;">
$(document).ready(function() {
   $().ready(function() {
        $('#nav').menu();
   });
});
</pre>
<p>The plugin has now been activated and the code within the function will be run on the #nav element.</p>
<p><strong>How: Making the plugin do something</strong><br />
This plugin is going to make a submenu slide down when the parent element is being hovered by the mouse. I will not go into details of the code other than the comments I have made below:</p>
<pre class="brush: jscript;">
(function($) {
    $.fn.menu = function() {
        // make sure there is a &lt;ul&gt;-submenu. If not - it will fail
        $(this).children(&quot;li&quot;).append('&lt;ul&gt;&lt;/ul&gt;');
        // add classes to the &lt;li&gt; and &lt;ul&gt;
        $(this).children(&quot;li&quot;).addClass(&quot;mmmenu&quot;);
        $(this).contents().find(&quot;ul&quot;).addClass(&quot;mmsub&quot;);

        // ready-state to prevent looping
        var ready = true;
        // when hover do this
        $(&quot;li.mmmenu&quot;).mouseenter(function() {
            // if plugin is ready, then continue
            if ( $(this).children(&quot;ul.mmsub&quot;).is(':visible') == false &amp;&amp; ready == true ) {
                ready = false;
                // hide all submenus
                $(&quot;ul.mmsub&quot;).hide();
                // display the selected submenu
                $(this).children(&quot;ul.mmsub&quot;).slideDown(500, function() {
                    ready = true;
                });
            }
        });
    }
})(jQuery);
</pre>
<p><strong>How: Passing options to the plugin</strong><br />
The above code will slide down the submenu at a speed of 500ms. But what if I would like to override this value? Lets add some options to the code as well:</p>
<pre class="brush: jscript;">
(function($) {
    $.fn.menu = function(options) {
        var defaults = {
            speed: 500,
        }; 

        var options = $.extend(defaults, options);
        ...
                $(this).children(&quot;ul.mmsub&quot;).slideDown(options.speed, function() {
                    ready = true;
                });
        ...
    }
})(jQuery);
</pre>
<p>The code now support options. There is a default option, where <code>speed</code> is set to <code>500</code>ms. and the <code>slideDown</code>-function is now using the <code>options</code>-variable.</p>
<p>To set the slide down speed to ie. <code>2000</code>ms, then pass the option like this:</p>
<pre class="brush: jscript;">
$(document).ready(function() {
   $().ready(function() {
        $('#nav').menu({speed: 2000,});
   });
});
</pre>
<p>There you go. If you would like to download the mmmenu-plugin, just <a href="/js/jquery.mmmenu.js">click here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/howto-make-a-jquery-menu-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery and iframe manipulation</title>
		<link>http://huuah.com/jquery-and-iframe-manipulation/</link>
		<comments>http://huuah.com/jquery-and-iframe-manipulation/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 10:52:48 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[iframe]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=248</guid>
		<description><![CDATA[<p>I&#8217;ve been experimenting with some iframe-manipulation with jQuery, but this was not as easy as I have hoped for. There is not much help on jquery.com and a Google search just found others with the same kind of problem.</p>
<p>My setup is very basic. An iframe loading a page like&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been experimenting with some iframe-manipulation with jQuery, but this was not as easy as I have hoped for. There is not much help on jquery.com and a Google search just found others with the same kind of problem.</p>
<p>My setup is very basic. An iframe loading a page like this </p>
<pre class="brush: xml;">&lt;iframe name=&quot;framename&quot; id=&quot;myframe&quot; src=&quot;mypage.html&quot;&gt;&lt;/iframe&gt;</pre>
<p>In the page where this iframe is being loaded, I have included the jquery.min.js and an extra .js-file for my code.</p>
<div class="bt">
<script type="text/javascript"><!--
amazon_ad_tag="huuah-21"; 
amazon_ad_width="468"; 
amazon_ad_height="60"; 
amazon_color_background="F5F5F5"; 
amazon_color_border="337696"; 
amazon_color_logo="FFFFFF"; 
amazon_color_link="0088CC"; 
amazon_ad_logo="hide"; 
amazon_ad_link_target="new"; 
amazon_ad_title="jQuery Book"; //--></script><br />
<script type="text/javascript" src="http://www.assoc-amazon.co.uk/s/asw.js"></script>
</div>
<p><strong>First attempt</strong> was to try the examples found on Google. For testing purposes I wanted to set a red background color on every &lt;div&gt; inside the iframe.</p>
<pre class="brush: jscript;">var frame = $(&quot;#myframe&quot;)[0].contentDocument;
$(&quot;div&quot;, frame).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>Nothing happens.</p>
<p>When testing new things I often use alert-boxes for test-output, so I tried inserting an alert-box:</p>
<pre class="brush: jscript; highlight: [1];">alert(&quot;trying a red color&quot;);
var frame = $(&quot;#myframe&quot;)[0].contentDocument;
$(&quot;div&quot;, frame).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>And hey! When pushing the alert-box, the divs inside the iframe gets a red background-color. Or at least they do in Firefox 3.0.11 (still a no-go in IE8). Strange.</p>
<p><strong>Test 2</strong>:</p>
<pre class="brush: jscript;">$(&quot;#myframe&quot;).contents().find(&quot;div&quot;).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>Nothing! Blank!</p>
<p>Oh well. Why not try the alert-box again:</p>
<pre class="brush: jscript; highlight: [1];">alert(&quot;trying a red color&quot;);
$(&quot;#myframe&quot;).contents().find(&quot;div&quot;).css(&quot;background-color&quot;, &quot;red&quot;);</pre>
<p>Hmm.. this seems to work in both Firefox 3.0.11 and Internet Explorer 8 <strong>IF</strong> you <strong>don&#8217;t</strong> push the alert-box until the iframe is finished loading.</p>
<p>So perhaps it&#8217;s all about not accessing the iframe before the contents has been loaded. So I tried wrapping the whole thing in a ready-function like this:</p>
<pre class="brush: jscript;">$(&quot;#myframe&quot;).ready(function () {
...
}</pre>
<p>That did <strong>not</strong> help at all. </p>
<p>Well. Google google google. And bingo. There&#8217;s a plugin for jQuery called <a href="http://ideamill.synaptrixgroup.com/wp-trackback.php?p=6">frameReady</a> and this does the trick.</p>
<div class="ww">
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1430230541?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430230541"><img border="0" src="/512a8p3m4KL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430230541" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0596101694?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0596101694"><img border="0" src="/415wDIPoM8L._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0596101694" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0240813286?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0240813286"><img border="0" src="/515T2pj0xRL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0240813286" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1935182323?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1935182323"><img border="0" src="/51Mz3glo-7L._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1935182323" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0596101996?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0596101996"><img border="0" src="/51IJ8LZqxmL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0596101996" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
</div>
<p><strong>Third and final test</strong>:<br />
Include the jQuery.frameReady.js in the main page and enter this code:</p>
<pre class="brush: jscript;">$.frameReady( function() {
    $(&quot;div&quot;).css(&quot;background&quot;, &quot;red&quot;);
  },
  &quot;framename&quot;
);</pre>
<p>This loads the iframe and sets a red background color on every div inside the iframe. Tested in IE8 and Firefox 3.0.11.</p>
<p><strong>Conclusion</strong>:<br />
Use the <a href="http://ideamill.synaptrixgroup.com/wp-trackback.php?p=6">frameReady</a> plugin for jQuery when manipulating with iframes.</p>
<p>Update: If you&#8217;re having trouble getting this to work, please check the source code for frameReady and verify that the hardcoded path for /js/jQuery.js matches your site configuration!</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/jquery-and-iframe-manipulation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery and Flot demo</title>
		<link>http://huuah.com/jquery-and-flot-demo/</link>
		<comments>http://huuah.com/jquery-and-flot-demo/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 19:24:28 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[flot]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=147</guid>
		<description><![CDATA[<p>I previously posted some info about plotting data with jQuery and Flot and I have now set up a small demonstration:</p>
<p>The data value below are 100% random generated numbers, but they will simulate data from a database (or anything else for that matter). It consists of an array, where&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I previously posted some info about plotting data with jQuery and Flot and I have now set up a small demonstration:</p>
<p>The data value below are 100% random generated numbers, but they will simulate data from a database (or anything else for that matter). It consists of an array, where the first parameter the a Unix timestamp (multiplied by 1000) and the second parameter is the value to be drawed.<br />
<textarea id="randomnumber" rows="10" cols="50"></textarea><br />
<button id="generaterandomnumbers">Generate a list of numbers</button><br />
Push the generate button to get a new dataset.</p>
<p>You can also try to change some of the values, to see that happens. Just push the update button below, to have your changes updated.<br />
<button id="draw">Update graph if values has changed</button></p>
<p>The graph:</p>
<div id="livejquery"></div>
<p>The code to output the graph is:</p>
<pre class="brush: plain;">
        var options = {
            xaxis: {
                mode: &quot;time&quot;,
                timeformat: &quot;%y/%m/%d %h:%M&quot;
            },
            lines: {
                show: true,
            },
        };

        var data = [];
        data = eval($(&quot;#randomnumber&quot;).val());
        $.plot($(&quot;#livejquery&quot;), data, options);
</pre>
<p>I have set a few options (goto the Flot API for futher options) &#8211; the xasis should convert the unix timestamp to a human readable format and the graph should output a <em>line</em>. I am only using the eval()-function because I have to convert the string input from the textarea (class #randomnumber) to an array. </p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/jquery-and-flot-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plotting user statistics using jQuery and flot</title>
		<link>http://huuah.com/plotting-user-statistics-using-jquery-and-flot/</link>
		<comments>http://huuah.com/plotting-user-statistics-using-jquery-and-flot/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 20:55:01 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=74</guid>
		<description><![CDATA[<p>Hit statistics from visiting website users stored in a database. Then what? How do I list these log entries in a very simple way. The only important thing for now, is when the visitor came by the site.</p>
<p>The database stores a timestamp and which page the user visited. This&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Hit statistics from visiting website users stored in a database. Then what? How do I list these log entries in a very simple way. The only important thing for now, is when the visitor came by the site.</p>
<p>The database stores a timestamp and which page the user visited. This can mean a massive amount of data and I don&#8217;t know how this first attempt will perform. At the moment, there is a relative small amount of data, but in time this should build up and if the performance starts lacking, I will take a look at it again.</p>
<p>To output the data to the user I will be using jQuery and the <a href="http://code.google.com/p/flot/">flot</a> graphic tool. Before starting drawing I how to figure out, how to group my visitors. There no point in plotting a bunch of &#8217;1 hits&#8217; &#8211; is will make no sence, since the graph never will go above 1 hit pr entry. The data should therefor be grouped and I&#8217;m going to use the GROUP BY function i MySQL.</p>
<p>Which interval should the data be grouped in? I don&#8217;t know &#8211; it probably depends on the data. In my case I will group it into 5 minuttes (300 seconds) interval and this in done here:</p>
<pre class="brush: php;">SELECT tstamp, count(tstamp) as hits FROM visitorlog GROUP BY FLOOR(tstamp/300)</pre>
<p>This gives me an output like this:</p>
<pre class="brush: php;">1244825201 7
1244826384 8
1244826803 16
1244826904 3
1244827259 1
1244827506 10
</pre>
<p>And now all I have to do, is plot the numbers using flot. The output will be generated from PHP and will end up looking like this:</p>
<pre class="brush: php;">
$(document).ready (function() {

var data = [
  [[1244825201*1000,0], [1244825201*1000,7]],
  [[1244826384*1000,0], [1244826384*1000,8]],
  [[1244826803*1000,0], [1244826803*1000,16]],
  [[1244826904*1000,0], [1244826904*1000,3]],
  [[1244827259*1000,0], [1244827259*1000,1]],
  [[1244827506*1000,0], [1244827506*1000,10]],
];
$.plot($(&quot;#chartdiv&quot;), data);

});</pre>
<p>Because I want a the graph to draw pins I will generate a line from point 0 to the number of hits in the given time period. The unix-timestamp is multiplied by 1000 to comply with the flot documentation.</p>
<p>This will generate a graph, which will be insert in the HTML ID <code>chartdiv</code>.</p>
<p>Result:<br />
<img src="http://huuah.com/images/jquery-and-flot.png" alt="jQuery flot graph" /></p>
<p>Remember &#8211; this is just a simple demo. With more data added (and better timestamps) it will be a lot better <img src='http://huuah.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Resources:<br />
<a href="http://jquery.com/">jQuery</a><br />
<a href="http://code.google.com/p/flot/">flot</a><br />
<a href="http://people.iola.dk/olau/flot/examples/">flot examples</a><br />
<a href="http://people.iola.dk/olau/flot/API.txt">flot API</a></p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/plotting-user-statistics-using-jquery-and-flot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
