<?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>BRADINO &#187; JavaScript</title>
	<atom:link href="http://www.bradino.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bradino.com</link>
	<description>Just another Wordpress blog</description>
	<lastBuildDate>Wed, 09 Nov 2011 20:09:20 +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>Pass Extra Parameters to JavaScript Callback Function</title>
		<link>http://www.bradino.com/javascript/pass-extra-parameters-to-javascript-callback-function/</link>
		<comments>http://www.bradino.com/javascript/pass-extra-parameters-to-javascript-callback-function/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 20:49:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4898</guid>
		<description><![CDATA[Here is a simple example of a function that takes a callback function as a parameter. &#160; query.send&#40;handleQueryResponse&#41;; &#160; function handleQueryResponse&#40;response&#41;&#123; &#160; alert&#40;'Processing...'&#41;; &#160; &#125; If you wanted to pass extra variables to the callback function, you can do it like this. &#160; var param1 = 'something'; &#160; var param2 ='something else'; &#160; query.send&#40;function&#40;response&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple example of a function that takes a callback function as a parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
query.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>handleQueryResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> handleQueryResponse<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Processing...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you wanted to pass extra variables to the callback function, you can do it like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> param1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">'something'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> param2 <span style="color: #339933;">=</span><span style="color: #3366CC;">'something else'</span><span style="color: #339933;">;</span>
&nbsp;
query.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> handleQueryResponse<span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span> param1<span style="color: #339933;">,</span> param2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> handleQueryResponse<span style="color: #009900;">&#40;</span>response<span style="color: #339933;">,</span>param1<span style="color: #339933;">,</span>param2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Processing...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>param1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>param2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/pass-extra-parameters-to-javascript-callback-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replace Listmenu with Textfield</title>
		<link>http://www.bradino.com/javascript/replace-listmenu-with-textfield/</link>
		<comments>http://www.bradino.com/javascript/replace-listmenu-with-textfield/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 00:36:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4819</guid>
		<description><![CDATA[Say you have a dropdown form field where you ask the user how they heard about you. You have numerous options and also an other field where if they selected other, then they enter the value in a text field. This is a cleaner alternative where if the user selects Other, then the dropdown turns [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a dropdown form field where you ask the user how they heard about you. You have numerous options and also an other field where if they selected other, then they enter the value in a text field. This is a cleaner alternative where if the user selects Other, then the dropdown turns into a textfield of the same name, so that your post routine, grooming, validation, writing to DB etc all works seamlessly. This example uses prototype JS library.</p>
<p>Here is a working example:</p>
<p><em>How did you hear about BRADINO?<em></p>
<select id="how-heard" name="how-heard" onchange="overrideListmenu('how-heard');">
<option value="Select">Select</option>
<option value="Google">Google</option>
<option value="Google">Yahoo</option>
<option value="Google">MSN</option>
<option value="Other">Other</option>
</select>
<p>All you have to do is have an dropdown option for Other and then add call the function onchange:</p>
<p><strong>onchange=&#8221;overrideListmenu(&#8216;how-heard&#8217;);&#8221;</strong></p>
<p>Here is the javascript function that uses <strong>Prototype</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> overrideListmenu<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$F<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'Other'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		Element.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'&lt;input name=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; id=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; type=&quot;text&quot; value=&quot;&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is the javascript function that uses <strong>jQuery</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> overrideListmenu<span style="color: #009900;">&#40;</span>field<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>field<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: #3366CC;">'Other'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input name=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; id=&quot;'</span><span style="color: #339933;">+</span>field<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; type=&quot;text&quot; value=&quot;&quot;&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>field<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/replace-listmenu-with-textfield/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PPC Conversion Tracking using Javascript</title>
		<link>http://www.bradino.com/javascript/ppc-conversion-tracking/</link>
		<comments>http://www.bradino.com/javascript/ppc-conversion-tracking/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 17:37:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4780</guid>
		<description><![CDATA[PPC Conversion tracking (Google/Yahoo/MSN) is straightforward for simple HTML websites. You place the conversion pixel on the thank you page. But when you have conversions in Flash sites or when the page is not reloaded after a conversion in the case of an ajaxed site, firing the conversion pixel is not as simple. I created [...]]]></description>
			<content:encoded><![CDATA[<p>PPC Conversion tracking (Google/Yahoo/MSN) is straightforward for simple HTML websites. You place the conversion pixel on the thank you page. But when you have conversions in Flash sites or when the page is not reloaded after a conversion in the case of an ajaxed site, firing the conversion pixel is not as simple.</p>
<p>I created a simple javascript function that will include the tracking pixel as an iframe in the current page. All you have to do is change the url to the tracking pixel and then call the conversion function from your page or flash file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> conversion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> iframe <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'iframe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	iframe.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0px'</span><span style="color: #339933;">;</span>
&nbsp;
	iframe.<span style="color: #660066;">style</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0px'</span><span style="color: #339933;">;</span> 
&nbsp;
	document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>iframe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	iframe.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://wwww.domain.com/pixel.html'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/ppc-conversion-tracking/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Analytics Goals</title>
		<link>http://www.bradino.com/javascript/google-analytics-goals/</link>
		<comments>http://www.bradino.com/javascript/google-analytics-goals/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 17:07:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://www.bradino.com/?p=4760</guid>
		<description><![CDATA[Goals in Google Analytics are one of my favorite features of this amazing free web analytics software. Goals allow you to track actions and then analyze how different traffic segments convert to these actions. Common actions would be completing a lead form, downloading a brochure, clicking the link for directions, etc. Goals are usually implemented [...]]]></description>
			<content:encoded><![CDATA[<p>Goals in Google Analytics are one of my favorite features of this amazing <a href="https://www.google.com/analytics/" target="_blank">free web analytics software</a>. Goals allow you to track actions and then analyze how different traffic segments convert to these actions. Common actions would be completing a lead form, downloading a brochure, clicking the link for directions, etc. Goals are usually implemented by entering the page url where the conversion occurs (Ex: thankyou.html). So how can we implement the goal tracking on sites where the form is the same url as the thank you page, or where the click leaves the site or goes to a non-html page? These can all be done easily by selecting Exact Match as the Match Type and then inserting a fictitious url like /goal/rfi/ for the Goal URL.</p>
<p>Let&#8217;s look at the first scenario where someone completes a lead form. Often forms submit to themselves, so you can&#8217;t have the goal conversion on the thank you page because it is the same url. These type of dynamic pages can easily fire off goals we just have to do it a different way. When the form is completed successfully, we just make a javascript call in the onload. Notice the /goal/rfi/ from the Goal URL setup.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>body <span style="color: #000066;">onload</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;pageTracker._trackPageview('/goal/rfi/');&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>So what if you want to track an exit click or a non-html file download (Ex: PDF Brochure). The idea is the same, you simply call the function from the onclick event handler.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;PrettyBrochure.pdf&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;pageTracker._trackPageview('/goal/rfi/');&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>Be sure that you have the New Tracking Code (ga.js) not the Legacy Tracking Code (urchin.js)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/google-analytics-goals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Split Function</title>
		<link>http://www.bradino.com/javascript/split-function/</link>
		<comments>http://www.bradino.com/javascript/split-function/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 07:16:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/javascript/split-2/</guid>
		<description><![CDATA[The Javascript split() function works much the same as the php split() or explode() functions. Basically you take a string at break it up everywhere the delimiter character occurs and return the new strings in an array. So for example, let&#8217;s say you have a string like this: [js]var colorString = &#8220;red&#124;orange&#124;blue&#124;white&#124;black&#124;brown&#8221;;[/js] Which is obviously [...]]]></description>
			<content:encoded><![CDATA[<p>The Javascript split() function works much the same as the php split() or explode() functions. Basically you take a string at break it up everywhere the delimiter character occurs and return the new strings in an array. So for example, let&#8217;s say you have a string like this:</p>
<p>[js]var colorString = &#8220;red|orange|blue|white|black|brown&#8221;;[/js]</p>
<p>Which is obviously a simple a pipe-delimited string of colors. So to make this into an array we would use the split function.</p>
<p>[js]var colorArray = colorString.split(&#8220;|&#8221;);[/js]</p>
<p>Now you have a simple array of colors and can access them as you would any array, either in a loop or by the numeric index, whatever&#8230;</p>
<p>[js]<br />
var message = &#8220;My favorite color is &#8221; + colorArray[3] ;<br />
alert(message);<br />
[/js]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/split-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jump to Location Within Page</title>
		<link>http://www.bradino.com/javascript/jump-to-location-within-page/</link>
		<comments>http://www.bradino.com/javascript/jump-to-location-within-page/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 20:22:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/javascript/jump-to-location-within-page/</guid>
		<description><![CDATA[I know of three very easy ways to jump to a location within a page. They are using the scrollTo() function, the window.location.hash function, and the Prototype scrollTo() function. This example uses the Javascript scrollTo() function where you simply pass the X,Y pixel coordinates that you want to jump the page to. This example would [...]]]></description>
			<content:encoded><![CDATA[<p>I know of three very easy ways to jump to a location within a page. They are using the scrollTo() function, the window.location.hash function, and the Prototype scrollTo() function.</p>
<p>This example uses the Javascript scrollTo() function where you simply pass the X,Y pixel coordinates that you want to jump the page to. This example would jump the page to the top:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;self.scrollTo(0,0);&quot;</span></pre></div></div>

<p>The second way I have done this is to create a named anchor and use the javascript window.location.hash function to jump to it. So basically create a named anchor called &#8220;JUMP2&#8243; or whatever you like and then make it happen like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;window.location.hash='JUMP2';&quot;</span></pre></div></div>

<p>And for my personal favorite, using Prototype you can jump the page to any html element. So basically give some element an id of &#8220;JUMP2&#8243; or whatever you like and then make it happen like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;$('JUMP2').scrollTo();</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/jump-to-location-within-page/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript Substring</title>
		<link>http://www.bradino.com/javascript/javascript-substring/</link>
		<comments>http://www.bradino.com/javascript/javascript-substring/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 16:57:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/javascript/javascript-substring/</guid>
		<description><![CDATA[The Javascript substring function is very similar to that of PHP. The first parameter is the start position and the second parameter is the end position. The first character in a javascript string is position 0. Here is a simple example: var birthday = '1978-07-11' var year = birthday.substring&#40;0,4&#41; var month = birthday.substring&#40;5,7&#41; var day [...]]]></description>
			<content:encoded><![CDATA[<p>The Javascript substring function is very similar to that of PHP. The first parameter is the start position and the second parameter is the end position. The first character in a javascript string is position 0.</p>
<p>Here is a simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> birthday <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1978-07-11'</span>
<span style="color: #003366; font-weight: bold;">var</span> year <span style="color: #339933;">=</span> birthday.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span>
<span style="color: #003366; font-weight: bold;">var</span> month <span style="color: #339933;">=</span> birthday.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span><span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span>
<span style="color: #003366; font-weight: bold;">var</span> day <span style="color: #339933;">=</span> birthday.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/javascript-substring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript For Loop</title>
		<link>http://www.bradino.com/javascript/for-loop/</link>
		<comments>http://www.bradino.com/javascript/for-loop/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 17:33:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/javascript/for-loop/</guid>
		<description><![CDATA[Here is an example of the JavaScript for loop (which is identical to the PHP for loop). Again I used Prototype. This basic example illustrates hiding multiple divs. So for example if you dynamically generate a page with divs you can show or hide them with an onchange() function call to something like this. if [...]]]></description>
			<content:encoded><![CDATA[<p>Here is an example of the JavaScript for loop (which is identical to the PHP for loop). Again I used Prototype. This basic example illustrates hiding multiple divs. So for example if you dynamically generate a page with divs you can show or hide them with an onchange() function call to something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$F<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'validationid'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'18'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">10</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> Element.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'subsetList'</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Onclick Return False</title>
		<link>http://www.bradino.com/javascript/onclick-return-false/</link>
		<comments>http://www.bradino.com/javascript/onclick-return-false/#comments</comments>
		<pubDate>Tue, 15 May 2007 21:47:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/javascript/onclick-return-false/</guid>
		<description><![CDATA[Anywhere you put an onclick event with a javascript call, if you add return false then the default behavior (what would have happened without the onclick event) will be disregarded. For example: [html]Click Me[/html] So now when a user clicks the link, the doSomething() function will fire off and the user will not go to [...]]]></description>
			<content:encoded><![CDATA[<p>Anywhere you put an onclick event with a javascript call, if you add return false then the default behavior (what would have happened without the onclick event) will be disregarded.</p>
<p>For example:</p>
<p>[html]<a href="http://www.nojs.com" onclick="doSomething(); return false;">Click Me</a>[/html]</p>
<p>So now when a user clicks the link, the doSomething() function will fire off and the user will not go to http://www.nojs.com (unless they do not have javascript enabled).</p>
<p>To take it one step further, you can use the confirm function to force the user to confirm that they want to go to the link and then if they say ok then return true. For example:</p>
<p>[html]<a href="http://www.nojs.com" onclick="return confirm('Are you sure you want to do that?');">Click Me</a>[/html]</p>
<p>And one final tidbit, soemthing I find irritating is when I use a link to AJAX something or toggle a div and then after I click the link and the onclick function fires off, the link is still selected. I know it doesn&#8217;t matter, whatever, here is a little hack you can do to keep this from happening. You basically &#8220;blur&#8221; the focus which is like unfocus. Here is a simple example:</p>
<p>[html]<a href="" id="bjd" onclick="Element.toggle('MyDiv'); $('bjd').blur(); return false;">Toggle MyDiv</a>[/html]</p>
<p>The preceding assumes that you are using prototype. If you are not using prototype then you need to start and you can get it and learn all about it here: <a href="http://www.bradino.com/javascript/prototype-javascript-framework/">Prototype</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/onclick-return-false/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Form List Key to Index</title>
		<link>http://www.bradino.com/javascript/form-list-key-to-index/</link>
		<comments>http://www.bradino.com/javascript/form-list-key-to-index/#comments</comments>
		<pubDate>Thu, 29 Mar 2007 20:58:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.bradino.com/javascript/form-list-key-to-index/</guid>
		<description><![CDATA[JavaScript references list menu (dropdown) elements by their index number, not by the list menu&#8217;s key. So if you want to preselect a list menu using JavaScript and you know they key in the key/value pairs that comprise the listmenu, here is a simple function I wrote which you pass the field id and the [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript references list menu (dropdown) elements by their index number, not by the list menu&#8217;s key. So if you want to preselect a list menu using JavaScript and you know they key in the key/value pairs that comprise the listmenu, here is a simple function I wrote which you pass the field id and the key you want the index for.</p>
<p>[js]<br />
function key2index(field,value){<br />
	for (i=0; i<$(field).options.length; i++){<br />
		if ($(field).options[i].value == value)	return i;<br />
	} return 0;<br />
}<br />
[/js]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradino.com/javascript/form-list-key-to-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

