<?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>Sean&#039;s Blog &#187; javascript</title>
	<atom:link href="http://seanbehan.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Link to jQuery Source from Google&#8217;s CDN</title>
		<link>http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/</link>
		<comments>http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/#comments</comments>
		<pubDate>Sat, 28 May 2011 17:09:44 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips & snippets]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[page load]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1324</guid>
		<description><![CDATA[https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js That is the link to the jQuery source hosted by Google on their CDN. It&#8217;s probably already cached on client machines so it should be as fast as is possible! You can read more/use other Javascript libs from Google&#8217;s CDN here: http://code.google.com/apis/libraries/devguide.html#jquery]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Ffront-end-development%2Flink-to-jquery-source-from-googles-cdn%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Link to jQuery Source from Google&#8217;s CDN" data-url="http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js</p>
<p>That is the link to the jQuery source hosted by Google on their CDN. It&#8217;s probably already cached on client machines so it should be as fast as is possible! You can read more/use other Javascript libs from Google&#8217;s CDN here: <a href="http://code.google.com/apis/libraries/devguide.html#jquery">http://code.google.com/apis/libraries/devguide.html#jquery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3 disable_with Does Not Work with Ajax Remote Form_for</title>
		<link>http://seanbehan.com/front-end-development/rails-3-disable_with-does-not-work-with-ajax-remote-form_for/</link>
		<comments>http://seanbehan.com/front-end-development/rails-3-disable_with-does-not-work-with-ajax-remote-form_for/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 17:40:50 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[disable_with]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails 3]]></category>
		<category><![CDATA[rails helpers]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1267</guid>
		<description><![CDATA[It appears that the :disable_with option on the submit_tag form helper method does not behave as expected with remote forms. I&#8217;m not sure if this is a bug or not. But the fix is pretty straight forward, but perhaps a little difficult to trouble shoot. Using submit_tag inside a remote form &#38;lt;%= submit_tag &#34;Submit&#34;, :disable_with [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Ffront-end-development%2Frails-3-disable_with-does-not-work-with-ajax-remote-form_for%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Rails 3 disable_with Does Not Work with Ajax Remote Form_for" data-url="http://seanbehan.com/front-end-development/rails-3-disable_with-does-not-work-with-ajax-remote-form_for/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>It appears that the :disable_with option on the submit_tag form helper method does not behave as expected with remote forms. I&#8217;m not sure if this is a bug or not. But the fix is pretty straight forward, but perhaps a little difficult to trouble shoot. Using submit_tag inside a remote form</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;%= submit_tag &quot;Submit&quot;, :disable_with =&amp;gt; &quot;Submitting....&quot; %&amp;gt;
</pre>
<p>Will not work.</p>
<p>You have to edit your public/javascripts/rails.js file around line #167</p>
<p>and change</p>
<pre class="wp-code-highlight prettyprint">document.on(&quot;ajax:after&quot;, &quot;form&quot;, function(event, element) {</pre>
<p>to</p>
<pre class="wp-code-highlight prettyprint">document.on(&quot;ajax:complete&quot;, &quot;form&quot;, function(event, element) {</pre>
<p>Then things will behave as expected. This assumes you are using Prototype (rather than jQuery).</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/front-end-development/rails-3-disable_with-does-not-work-with-ajax-remote-form_for/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Execute Javascript When Using Link_to_function To Include a Partial in Rails</title>
		<link>http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/</link>
		<comments>http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 23:34:02 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[link_to_function]]></category>
		<category><![CDATA[partial]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[replace_html]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1220</guid>
		<description><![CDATA[If you use the link_to_function to replace content in a div with content from a partial, any javascript that you include in the partial will not be executed. It is instead included, but will do nothing. Obviously, this isn&#8217;t the desired behavior. Why would we be taking the trouble to write the javascript in the [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fjavascript%2Fexecute-javascript-when-using-link_to_function-to-include-a-partial-in-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Execute Javascript When Using Link_to_function To Include a Partial in Rails" data-url="http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>If you use the link_to_function to replace content in a div with content from a partial, any javascript that you include in the partial will not be executed. It is instead included, but will do nothing. Obviously, this isn&#8217;t the desired behavior. Why would we be taking the trouble to write the javascript in the partial? There is an easy fix. Instead of writing out the script tags, instead use the javascript_tag  method to wrap whatever javascript you would like executed when the partial is loaded.</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;%=link_to_function &quot;say hello&quot; {|p| p.replace_html &quot;container&quot;, :partial =&amp;gt; &quot;say_hello&quot; }%&amp;gt;</pre>
<p>And now in my say_hello.erb file</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;% javascript_tag do %&amp;gt;
  alert(&quot;Hello World&quot;);
&amp;lt;% end %&amp;gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Links in Nested TD Cells with Prototype</title>
		<link>http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/</link>
		<comments>http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 21:59:42 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[$$]]></category>
		<category><![CDATA[code optimization]]></category>
		<category><![CDATA[nested]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[td]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=618</guid>
		<description><![CDATA[There must be a better way to do the following with PrototypeJS. I want to loop over nested links inside of table td cells and apply a class to the row that the link is in when the link is clicked. If a user clicks on another link the class will be removed and applied [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fjavascript%2Faccessing-links-in-nested-td-cells-with-prototype%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Accessing Links in Nested TD Cells with Prototype" data-url="http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>There must be a better way to do the following with PrototypeJS. I want to loop over nested links inside of  table td cells and apply a class to the row that the link is in when the link is clicked. If a user clicks on another link the class will be removed and applied to the current table row.</p>
<p>The code below works but I think it seems hackish. Any thoughts on improving this code?</p>
<p>Here is the link to the pastie <a href="http://pastie.org/703316">http://pastie.org/703316</a></p>
<pre class="wp-code-highlight prettyprint">
# This is the table with haml markup
%table
  %tr
    %td
       info
    %td
      = link_to &quot;be clicked&quot;, remote_request_goes_here_path
</pre>
<p>And the Js</p>
<pre class="wp-code-highlight prettyprint">
	$$(&quot;td.filter_link &gt; a&quot;).each(function(element){
		Event.observe(element, &quot;click&quot;, function(event){
			$$(&quot;td.filter_link&quot;).each(function(el){
				if(el != this){
					el.up().removeClassName(&quot;turnwhite&quot;);
				}
			});
                       // apply the turnwhite class to the table row
			this.up().up().addClassName(&quot;turnwhite&quot;);
		});
	});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TinyMCE Rich Text Editor: HELLO EDITOR Plugin Tutorial and Example</title>
		<link>http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/</link>
		<comments>http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 19:26:52 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[text editor]]></category>
		<category><![CDATA[tinymce]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=598</guid>
		<description><![CDATA[I wanted to create a button for the TinyMCE Rich Text Editor for WordPress. It was tough to find good docs on the subject. There are a couple of useful posts out there but in general I found them lacking. http://codex.wordpress.org/TinyMCE_Custom_Buttons#Creating_an_MCE_Editor_Plugin The above resource has a good section on the PHP code needed to write [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fwordpress%2Ftinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="TinyMCE Rich Text Editor: HELLO EDITOR Plugin Tutorial and Example" data-url="http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I wanted to create a button for the TinyMCE Rich Text Editor for WordPress. It was tough to find good docs on the subject. There are a couple of useful posts out there but in general I found them lacking.<br />
<a href=" http://codex.wordpress.org/TinyMCE_Custom_Buttons#Creating_an_MCE_Editor_Plugin"></p>
<p>http://codex.wordpress.org/TinyMCE_Custom_Buttons#Creating_an_MCE_Editor_Plugin</a></p>
<p>The above resource has a good section on the PHP code needed to write your own callbacks but there is no mention of the JavaScript required to create a button and interact with it. Links are available for more reading but why not also post a code sample to get up and running?</p>
<p>Anyway, I made a simple plugin after hobbling a bunch of resources together to get a button in the text editor that when clicked triggers an alert to the window. The code isn&#8217;t fancy but it might provide a starting off point for a larger project or be useful as a resource for some of the basic ideas involved. I read through a couple of the sample plugins included with WordPress along with the Viper Video Quicktags Plugin, which makes extensive use of the feature. However, they were too complex for a quick, basic understanding.</p>
<p>This plugin doesn&#8217;t do a lot. I&#8217;ll probably flesh it out a bit more when I have a clearer understanding of how it all works. For now here are some code samples and at the bottom of this post there is a link to the .zip file for the plugin which you can install on your own site.</p>
<p>In wp-content/plugins/hello_editor/index.php</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;?php
/*
Plugin Name: Hello Editor
Plugin URI: http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/
Description: A simple plugin showing how to add a button to the rich text editor in WordPress.
The plugin doesn't do anything except place a button and respond to onclick event, with &quot;Hello Editor&quot;.
Most of the editor plugins available are too 'functional' to quickly read and see how to do the
basics. This plugin doesn't 'do' anything, rather it makes it simple to read what is going on.
Version: 0.1
Author: Sean Behan
Author URI: http://seanbehan.com
*/

define( &quot;HELLO_EDITOR_PLUGIN_DIR&quot;, &quot;hello_editor&quot; );
define( &quot;HELLO_EDITOR_PLUGIN_URL&quot;, &quot;/wp-content/plugins/&quot; . HELLO_EDITOR_PLUGIN_DIR );

// Register the external pllugin from the .js file
function hello_editor_register_external_plugin($plugin_array) {
  $plugin_array['HELLO_EDITOR'] = HELLO_EDITOR_PLUGIN_URL . '/editor_plugin.js';
  return $plugin_array;
}

// Add the button to the array ***NOTE*** The name here &quot;HELLO_EDITOR&quot; must
//match the name in the editor plugin file for the addButton(name_of_button) function!
function hello_editor_register_button($buttons) {
  array_push( $buttons, &quot;|&quot;, &quot;HELLO_EDITOR&quot; );
  return $buttons;
}

// Filters which will call our functions
function hello_editor_init(){
  add_filter(&quot;mce_external_plugins&quot;, &quot;hello_editor_register_external_plugin&quot;);
  add_filter('mce_buttons', 'hello_editor_register_button');
}

// When the editor is initialized
add_action('init', 'hello_editor_init');</pre>
<p>In wp-content/plugins/hello_editor/editor_plugin.js</p>
<pre class="wp-code-highlight prettyprint">(function() {
  //Init the plugin
  tinymce.create('tinymce.plugins.HELLO_EDITOR', {
    init : function( ed, url ) {
    //addButton name needs to match $plugin_array['HELLO_EDITOR'] in add_filter function
    ed.addButton('HELLO_EDITOR', {
      title : 'Hello Editor',
      image : url + &quot;/buttons/hello.png&quot;,
      onclick : function(){
        alert(&quot;HELLO EDITOR!&quot;);
      }
    });
  },
  //Info about the plugin
  getInfo : function() {
    return {
      longname : &quot;Sean Behan's Sample Hello Editor Plugin&quot;,
      author : 'Sean Behan',
      authorurl : 'http://www.seanbehan.com/',
      infourl : 'http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/',
      version : &quot;0.1&quot;
    };
  }
});
tinymce.PluginManager.add('HELLO_EDITOR', tinymce.plugins.HELLO_EDITOR);
})();</pre>
<p>You&#8217;ll also need a directory called buttons inside the hello_editor plugin directory with a hello.png file which will be displayed. Without it you&#8217;ll just get a blank button. You can rename this but remember to change the name in the editor_plugin.js file as well.</p>
<p>You can download the sample plugin here <a href="http://seanbehan.com/wp-content/uploads/2009/11/hello_editor.zip">http://seanbehan.com/wp-content/uploads/2009/11/hello_editor.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Double Click Event Using Prototype Javascript Framework</title>
		<link>http://seanbehan.com/programming/double-click-event-using-prototype-javascript-framework/</link>
		<comments>http://seanbehan.com/programming/double-click-event-using-prototype-javascript-framework/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 18:15:55 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[double click]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=501</guid>
		<description><![CDATA[Super simple to get double click &#8220;desktop&#8221; like functionality out of Prototype! For some reason, googling it doesn&#8217;t yield many useful results. http://www.google.com/#hl=en&#038;q=double+click+in+prototype+javascript&#038;aq=f&#038;oq=&#038;aqi=&#038;fp=peEfEjG9pWY :( Anyway, here is the code document.observe('dblclick', function(){ alert(&#34;Hello World&#34;); });]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fprogramming%2Fdouble-click-event-using-prototype-javascript-framework%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Double Click Event Using Prototype Javascript Framework" data-url="http://seanbehan.com/programming/double-click-event-using-prototype-javascript-framework/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Super simple to get double click &#8220;desktop&#8221; like functionality out of Prototype! For some reason, googling it doesn&#8217;t yield many useful results. http://www.google.com/#hl=en&#038;q=double+click+in+prototype+javascript&#038;aq=f&#038;oq=&#038;aqi=&#038;fp=peEfEjG9pWY :(</p>
<p>Anyway, here is the code</p>
<pre class="wp-code-highlight prettyprint">
	document.observe('dblclick', function(){
		alert(&quot;Hello World&quot;);
	});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/double-click-event-using-prototype-javascript-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Prototype to Access Form Data</title>
		<link>http://seanbehan.com/programming/using-prototype-to-access-form-data/</link>
		<comments>http://seanbehan.com/programming/using-prototype-to-access-form-data/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 19:42:28 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://bseanvt.wordpress.com/?p=81</guid>
		<description><![CDATA[Prototype has a powerful API for accessing and manipulating the Document Object Model, A.K.A the DOM. The following code will let you interact with a simple web form. Suppose we have a form that contains hidden/or locked inputs and they need to be updated dynamically. If the user changes a select field or if a [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fprogramming%2Fusing-prototype-to-access-form-data%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Using Prototype to Access Form Data" data-url="http://seanbehan.com/programming/using-prototype-to-access-form-data/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Prototype has a powerful API for accessing and manipulating the Document Object Model, A.K.A the DOM. The following code will let you interact with a simple web form.</p>
<p>Suppose we have a form that contains hidden/or locked inputs and they need to be updated dynamically. If the user changes a select field or if a checkbox is de/selected, other values in the form need updating. This could be required when products have options and associated price points. If you want to offer the user the option to switch options without refreshing or navigation this is a simple and effective approach.</p>
<p>&#8230; Sample form&#8230;</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;input type=&quot;hidden&quot; name=&quot;option_plan_id&quot; id=&quot;option_plan_id&quot; value=&quot;1&quot;&amp;gt;&amp;lt;br/&amp;gt;
&amp;lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;150&quot; id=&quot;amount&quot;&amp;gt;

&amp;lt;select name=&quot;select-plan&quot; id=&quot;select-plan&quot;&amp;gt;
&amp;lt;option value=&quot;1, 150&quot;&amp;gt;
USD 150 - 1 person
&amp;lt;/option&amp;gt;
&amp;lt;option value=&quot;2, 200&quot;&amp;gt;
USD 200 - 2 people
&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;
</pre>
<p>In this example I want to update the values on the amount and option_plan_id input fields. The first thing I need to make sure of is that the page has fully loaded. I&#8217;ll make sure that my code executes in this context by placing it inside the document.observe method. I&#8217;ll then set up an observer on my select field and if it changes, make assignments. Now, in this example, I just saved the plan id and amount information as a string. In my javascript code I split apart the string and then make the assignments. There are other, probably better, ways of doing this. For instance you could store serialized data/json, and then work with it inside your event. This seems simple enough, however, you&#8217;ll have to pay attention in the future, if your storage format changes! Here is the sample Prototype javascript code</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&amp;gt;
document.observe(&quot;dom:loaded&quot;, function(){ //when dom is fully loaded do -
//update fields when option is selected
Event.observe('select-plan', 'change', function(event){
var data = this.getValue();
var plan = data.split(&quot;,&quot;).first(); //breaks apart by comma
var amount = data.split(&quot;,&quot;).last();
$('plan_option_id').setAttribute('value', plan);
$('amount').setAttribute('value', amount);
});
});
&amp;lt;/script&amp;gt;
</pre>
<p>Thats it for now!</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/using-prototype-to-access-form-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parse for Links with Prototype JS</title>
		<link>http://seanbehan.com/programming/parse-for-links-with-prototype-js/</link>
		<comments>http://seanbehan.com/programming/parse-for-links-with-prototype-js/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 15:23:06 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://bseanvt.wordpress.com/?p=79</guid>
		<description><![CDATA[Parsing for links with the Prototype javascript library is easy. Here is the pattern for finding links /(http&#124;https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^ =%&#38;amp;amp;:/~\+#]*[\w\-\@?^=%&#38;amp;amp;/~\+#])?/ And to implement it you can loop through your containers that might contain links document.observe(&#34;dom:loaded&#34;, function(){ var posts = $$(&#34;div#posts&#34;); for(var i = 0; i &#38;lt; posts.length; i++){ var link_regex = /(http&#124;https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^ =%&#38;amp;amp;:/~\+#]*[\w\-\@?^=%&#38;amp;amp;/~\+#])?/; var parsed_string = [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fprogramming%2Fparse-for-links-with-prototype-js%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Parse for Links with Prototype JS" data-url="http://seanbehan.com/programming/parse-for-links-with-prototype-js/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Parsing for links with the Prototype javascript library is easy. Here is the pattern for finding links</p>
<pre class="wp-code-highlight prettyprint">
/(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^
=%&amp;amp;amp;:/~\+#]*[\w\-\@?^=%&amp;amp;amp;/~\+#])?/
</pre>
<p>And to implement it you can loop through your containers that might contain links</p>
<pre class="wp-code-highlight prettyprint">
document.observe(&quot;dom:loaded&quot;, function(){
var posts = $$(&quot;div#posts&quot;);
for(var i = 0; i &amp;lt; posts.length; i++){
var link_regex = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^
=%&amp;amp;amp;:/~\+#]*[\w\-\@?^=%&amp;amp;amp;/~\+#])?/;
var parsed_string = posts[i].innerHTML.gsub(link_regex, '&amp;lt;a href=&quot;#{0}&quot;
target=&quot;_blank&quot;&amp;gt;#{0}&amp;lt;/a&amp;gt;');
posts[i].innerHTML = parsed_string;
}
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/parse-for-links-with-prototype-js/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

