<?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>Cultivate Web Design Melbourne - Development Blog &#187; Javascript</title>
	<atom:link href="http://cultivatewebdesign.com.au/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://cultivatewebdesign.com.au/blog</link>
	<description></description>
	<lastBuildDate>Thu, 12 Aug 2010 04:16:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Dynamically populate a select box with options using mootools</title>
		<link>http://cultivatewebdesign.com.au/blog/dynamically-populate-a-select-box-with-options-using-mootools/</link>
		<comments>http://cultivatewebdesign.com.au/blog/dynamically-populate-a-select-box-with-options-using-mootools/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 02:03:10 +0000</pubDate>
		<dc:creator>Chris Gunn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[melbourne]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[option]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://cultivatewebdesign.com.au/blog/?p=189</guid>
		<description><![CDATA[window.addEvent('domready',function(){ $$('input[name=Enquiry_type]').addEvent('change',function() { var Enquiry_Categories = [['option 1','option 2','option 3'],['option 4','option 5','option 6'],['option 7','option 8','option 9']]; $('Enquiry_Sub_Category').empty(); for(i=0; i&#60;Enquiry_Categories[$(this).get('value')].length; i++) { var option = Enquiry_Categories[$(this).get('value')][i]; $('Enquiry_Sub_Category').grab(new Element('option',{value: option, html: option})); } }); }); &#60;!-- when this is selected--&#62; &#60;select name=&#34;Enquiry_type&#34;&#62; &#60;option value=&#34;0&#34;&#62;select this for options 1,2,3&#60;/option&#62; &#60;option value=&#34;1&#34;&#62;select this for options 4,5,6&#60;/option&#62; &#60;option value=&#34;2&#34;&#62;select this [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: jscript;">

window.addEvent('domready',function(){
	$$('input[name=Enquiry_type]').addEvent('change',function()
	{	var Enquiry_Categories = [['option 1','option 2','option 3'],['option 4','option 5','option 6'],['option 7','option 8','option 9']];

		$('Enquiry_Sub_Category').empty();

		for(i=0; i&lt;Enquiry_Categories[$(this).get('value')].length; i++)
		{	var option = Enquiry_Categories[$(this).get('value')][i];
			$('Enquiry_Sub_Category').grab(new Element('option',{value: option, html: option}));
		}
	});
});
</pre>
<pre class="brush: xml;">
&lt;!-- when this is selected--&gt;
&lt;select name=&quot;Enquiry_type&quot;&gt;
&lt;option value=&quot;0&quot;&gt;select this for options 1,2,3&lt;/option&gt;
&lt;option value=&quot;1&quot;&gt;select this for options 4,5,6&lt;/option&gt;
&lt;option value=&quot;2&quot;&gt;select this for options 7,8,9&lt;/option&gt;
&lt;/select&gt;

&lt;!--this will get populated--&gt;
&lt;select name=&quot;Enquiry_Sub_Category&quot;&gt;
&lt;/select&gt;
</pre>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 10px; width: 1px; height: 1px; overflow: hidden;">
<pre>'option 1','option 1',</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://cultivatewebdesign.com.au/blog/dynamically-populate-a-select-box-with-options-using-mootools/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cross-browser drag and drop file upload</title>
		<link>http://cultivatewebdesign.com.au/blog/cross-browser-drag-and-drop-file-upload/</link>
		<comments>http://cultivatewebdesign.com.au/blog/cross-browser-drag-and-drop-file-upload/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 14:20:37 +0000</pubDate>
		<dc:creator>Chris Gunn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax file upload]]></category>
		<category><![CDATA[cross browser]]></category>
		<category><![CDATA[java applet]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://cultivatewebdesign.com.au/blog/?p=18</guid>
		<description><![CDATA[Unfortunatly we only lhave a few ways to upload files without reloading the whole page. You can do this by using an iframe, flash or through a java applet. Since applets support drag and drop, we can use it to create a drag and drop file uploader. This is the html to hold the java [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunatly we only lhave a few ways to upload files without reloading the whole page. You can do this by using an <a href="http://www.ajaxray.com/blog/2007/07/28/ajax-like-unobtrusive-file-upload/">iframe</a>, <a href="http://digitarald.de/project/fancyupload/">flash </a> or through a java applet. Since applets support drag and drop, we can use it to create a drag and drop file uploader. </p>
<p>This is the html to hold the java applet. We chuck in a text field so we can pass additional information with the applet&#8217;s file post.</p>
<pre class="brush: xml;">
    &lt;input id=&quot;meta-text&quot; /&gt;
    &lt;button onclick=&quot;javascript:document.applets.uploadApplet.setMetadata(document.getElementById('meta-text').value);&quot;&gt;Set metadata&lt;/button&gt;
    &lt;br /&gt;
    &lt;applet type=&quot;application/x-java-applet&quot; name=&quot;uploadApplet&quot; id=&quot;uploadApplet&quot; code=&quot;dndapplet/applet/DNDApplet&quot; archive=&quot;signed_dndapplet.jar&quot; mayscript=&quot;true&quot; scriptable=&quot;true&quot;&gt;
        &lt;param name=&quot;uploadPath&quot;                      value=&quot;uploader.php&quot;&gt;
        &lt;param name=&quot;funcNameHandleCurrentUpload&quot;     value=&quot;handleCurrentUpload&quot;&gt;
    &lt;/applet&gt;
</pre>
<p>When a file is draged and dropped into the applet, it submits the file to the location passed through the uploadPath param. The upload works the same way as any FILE/POST form submit. So we write some PHP to handle it and return how the upload went.</p>
<pre class="brush: php;">
$uploadPath = &quot;./uploads&quot;;
$maxfilesize = 30000; //kByte
$tmp_name  = $_FILES['uploadfile']['tmp_name'];
$file_name = $_FILES['uploadfile']['name'];
$tgt_path  = &quot;$uploadPath/$file_name&quot;;
$field_name = 'uploadfile';

if ($_FILES['uploadfile']['size'] &gt; $maxfilesize*1024)
   die (&quot;File exceeds maximum filesize: $maxfilesize kByte.&quot;);

if ( ! is_writable( $uploadPath) )
	die (&quot;Upload path is not writeable.&quot;);

if ( ! move_uploaded_file( $tmp_name, $tgt_path ) )
  die (&quot;Problem during upload.&quot;);

echo &quot;$file_name Upload successful. Metadata: &quot; . $_POST['metadata'];
</pre>
<p>Finally, we have to go back to the html page and write some javascipt to handle the value returned by the applet.</p>
<pre class="brush: jscript;">
function javascript_callback (return_str)
{	alert(return_str);
}
</pre>
<p>Now we are all done. You can download the demo and the source code <a href="http://cultivatewebdesign.com.au/demos/uploader/">live demo link</a> . If you want to change the appearance of the applet, you can edit the code .</p>
<p>Here&#8217;s the <a href="http://cultivatewebdesign.com.au/demos/uploader/">live demo link</a> and the <a href="http://cultivatewebdesign.com.au/demos/uploader/uploader.zip">full source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cultivatewebdesign.com.au/blog/cross-browser-drag-and-drop-file-upload/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>How to make a ajax request fail (on purpose)</title>
		<link>http://cultivatewebdesign.com.au/blog/how-to-make-a-ajax-request-fail-on-purpose/</link>
		<comments>http://cultivatewebdesign.com.au/blog/how-to-make-a-ajax-request-fail-on-purpose/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 17:48:21 +0000</pubDate>
		<dc:creator>Chris Gunn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax return false]]></category>
		<category><![CDATA[fail ajax request]]></category>
		<category><![CDATA[fail xhr request]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[onFail]]></category>
		<category><![CDATA[php headers]]></category>
		<category><![CDATA[set php headers]]></category>
		<category><![CDATA[xhr]]></category>

		<guid isPermaLink="false">http://cultivatewebdesign.com.au/blog/how-to-make-a-ajax-request-fail-on-purpose/</guid>
		<description><![CDATA[header('HTTP/1.1 500 Internal Server Error');]]></description>
			<content:encoded><![CDATA[<pre class="brush: php;">
		header('HTTP/1.1 500 Internal Server Error');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cultivatewebdesign.com.au/blog/how-to-make-a-ajax-request-fail-on-purpose/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JASON to retrive data from php and populate form fields</title>
		<link>http://cultivatewebdesign.com.au/blog/using-jason-to-retrive-data-from-php-and-populate-form-fields/</link>
		<comments>http://cultivatewebdesign.com.au/blog/using-jason-to-retrive-data-from-php-and-populate-form-fields/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 03:08:00 +0000</pubDate>
		<dc:creator>Chris Gunn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code example]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[JASON]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://cultivatewebdesign.com.au/blog/?p=96</guid>
		<description><![CDATA[Say we want to auto fill the rest of the fields when some one enters the member id, &#60;form&#62; Member id:&#60;input id=&#34;memberid&#34; /&#62;&#60;br /&#62; First name:&#60;input id=&#34;firstname&#34; /&#62;&#60;br /&#62; Last name:&#60;input id=&#34;lastname&#34; /&#62;&#60;br /&#62; Phone:&#60;input id=&#34;phone&#34; /&#62;&#60;br /&#62; Email:&#60;input id=&#34;email&#34; /&#62;&#60;br /&#62; &#60;input type=&#34;submit&#34; /&#62; &#60;/form&#62; Now we make a php file to simply return [...]]]></description>
			<content:encoded><![CDATA[<p>Say we want to auto fill the rest of the fields when some one enters the member id,</p>
<pre class="brush: xml;">
&lt;form&gt;
	Member id:&lt;input id=&quot;memberid&quot; /&gt;&lt;br /&gt;
	First name:&lt;input id=&quot;firstname&quot; /&gt;&lt;br /&gt;
	Last name:&lt;input id=&quot;lastname&quot; /&gt;&lt;br /&gt;
	Phone:&lt;input id=&quot;phone&quot; /&gt;&lt;br /&gt;
	Email:&lt;input id=&quot;email&quot; /&gt;&lt;br /&gt;
	&lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>Now we make a php file to simply return the memeber info from for a POSTed id.<br />
The use of JASON here will let us do a neat trick when populating the fields using Javascript.<br />
If the memebrs not found, setting the header to &#8217;500&#8242; will return fail for the jason request.</p>
<pre class="brush: php;">
//load_member.php
$id = mysql_escape_string($_POST['id']);
$array = mysql_fetch_assoc(mysql_query(&quot;SELECT firstname, lastname, phone, email FROM members WHERE id = '$id' &quot;));
if(is_array($array))
	echo json_encode($array);
else
	header('HTTP/1.1 500 Internal Server Error');
</pre>
<p>Now, when a user moves the curser out of the memeber id input box, we will call the php file above though a normal javascript POST request.</p>
<pre class="brush: jscript;">
$('memberid').addEvent('blur',function()
{	new Request.JSON(
	{	url: &quot;load_member.php&quot;,
		onFailure:function()
		{	alert(&quot;Sorry, we couldn't find the id.&quot;);
		},
		onSuccess: function(member)
		{	for (var member_details in member)
			{	$(member_details).set('value',member[member_details]);
			}
		}
	}).post({'id': this.get('value')});
});
</pre>
<p>If we named the form id&#8217;s the same as table fields or used</p>
<pre class="brush: sql;"> SELECT field_name AS html_id_name FROM table</pre>
<p>then we can use the &#8216;for loop&#8217; to populate the fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://cultivatewebdesign.com.au/blog/using-jason-to-retrive-data-from-php-and-populate-form-fields/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

