<?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>Beutelevision &#187; javascript</title>
	<atom:link href="http://beutelevision.com/blog2/topics/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://beutelevision.com/blog2</link>
	<description>by Thomas Beutel</description>
	<lastBuildDate>Fri, 14 Oct 2011 19:13:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='beutelevision.com' port='80' path='/blog2/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Find a Javascript parent node that matches a certain string</title>
		<link>http://beutelevision.com/blog2/2011/05/20/find-a-javascript-parent-node-that-matches-a-certain-string/</link>
		<comments>http://beutelevision.com/blog2/2011/05/20/find-a-javascript-parent-node-that-matches-a-certain-string/#comments</comments>
		<pubDate>Fri, 20 May 2011 23:12:35 +0000</pubDate>
		<dc:creator>Thomas Beutel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://beutelevision.com/blog2/?p=230</guid>
		<description><![CDATA[Here&#8217;s a small bit of javascript that I use in my Sencha Touch projects to find a parent with an id that matches a string.

function findParentNodeRegex(regex, childObj) {
  var testObj = childObj;
  var count = 1;
  while(!testObj.id.match(regex)) {
    //console.log('My name is ' + testObj.id + '. Let\'s try moving [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a small bit of javascript that I use in my Sencha Touch projects to find a parent with an id that matches a string.</p>
<p><code><br />
function findParentNodeRegex(regex, childObj) {<br />
  var testObj = childObj;<br />
  var count = 1;<br />
  while(!testObj.id.match(regex)) {<br />
    //console.log('My name is ' + testObj.id + '. Let\'s try moving up one level to see what we get.');<br />
    testObj = testObj.parentNode;<br />
    count++;<br />
  }<br />
  // now you have the object you are looking for - do something with it<br />
  //console.log('Finally found ' + testObj.id + ' after going up ' + count + ' level(s) through the DOM tree');<br />
  return testObj;<br />
}<br />
</code></p>
<p>Suppose that you tapped an paragraph element that was nested like so and &#8220;target&#8221; points to the paragraph:</p>
<p><code>&lt;div id="news1234"&gt;&lt;div class="content"&gt;&lt;p&gt;Tap me!&lt;p&gt;&lt;/div&gt;&lt;/div&gt;</code></p>
<p>You can find the parent that matches the string &#8220;news&#8221; like so:</p>
<p><code>var newsParent = findParentNodeRegex(/news/,target);<br />
console.log("Id is "+newsParent.id); // prints "Id is news1234"</code></p>
<p>I adapted the code from <a href="http://www.randomsnippets.com/2008/06/26/how-to-find-and-access-parent-nodes-via-javascript/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://beutelevision.com/blog2/2011/05/20/find-a-javascript-parent-node-that-matches-a-certain-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting a click in a checkbox with jQuery</title>
		<link>http://beutelevision.com/blog2/2010/03/20/detecting-a-click-in-a-checkbox-with-jquery/</link>
		<comments>http://beutelevision.com/blog2/2010/03/20/detecting-a-click-in-a-checkbox-with-jquery/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 16:07:50 +0000</pubDate>
		<dc:creator>Thomas Beutel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://beutelevision.com/blog2/?p=206</guid>
		<description><![CDATA[A simple script to detect when a checkbox is clicked. What you do with once you&#8217;ve detected the click is up to you.
 &#60;html&#62;
 &#60;head&#62;
 &#60;script src="http://www.google.com/jsapi"&#62;&#60;/script&#62;
 &#60;script&#62;
 google.load("jquery", "1.3.2");
 google.setOnLoadCallback(function() {
  $('#agree').click( function() {
    if($(this).attr('checked')){
      alert('checked');
    }
    else{
  [...]]]></description>
			<content:encoded><![CDATA[<p>A simple script to detect when a checkbox is clicked. What you do with once you&#8217;ve detected the click is up to you.<br />
<code> &lt;html&gt;<br />
 &lt;head&gt;<br />
 &lt;script src="<a href="http://www.google.com/jsapi">http://www.google.com/jsapi</a>"&gt;&lt;/script&gt;<br />
 &lt;script&gt;<br />
 google.load("jquery", "1.3.2");<br />
 google.setOnLoadCallback(function() {<br />
  $('#agree').click( function() {<br />
    if($(this).attr('checked')){<br />
      alert('checked');<br />
    }<br />
    else{<br />
      alert('unchecked');<br />
    }<br />
  });<br />
 });<br />
 &lt;/script&gt;<br />
 &lt;/head&gt;<br />
 &lt;body&gt;<br />
 &lt;p&gt;<br />
 &lt;input id="agree" type="checkbox" /&gt; I agree<br />
 &lt;/p&gt;<br />
 &lt;/body&gt;&lt;/html&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://beutelevision.com/blog2/2010/03/20/detecting-a-click-in-a-checkbox-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect from within a Wordpress admin page</title>
		<link>http://beutelevision.com/blog2/2010/03/19/redirect-from-within-wordpress-admi/</link>
		<comments>http://beutelevision.com/blog2/2010/03/19/redirect-from-within-wordpress-admi/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 04:11:01 +0000</pubDate>
		<dc:creator>Thomas Beutel</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://beutelevision.com/blog2/?p=201</guid>
		<description><![CDATA[I was trying to perform a redirect to generate a CSV file from within a Wordpress admin page using the wp_redirect( ) function, but the problem was that I would always get the dreaded &#8220;Cannot modify header information &#8211; headers already sent&#8221; message. This is because admin plugins are simply hooks that are performed within [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to perform a redirect to generate a CSV file from within a Wordpress admin page using the wp_redirect( ) function, but the problem was that I would always get the dreaded &#8220;Cannot modify header information &#8211; headers already sent&#8221; message. This is because admin plugins are simply hooks that are performed within the framework of the admin system.</p>
<p>The solution was to use a Javascript redirect. The Javascript attaches an event listener to listen for the &#8220;load&#8221; event. When the admin page is finished loading, a page containing the CSV data is loaded. That page has a Content-Type of application/csv, so it downloads immediately, leaving the admin page open (at least in Safari 4).</p>
<p>In my Wordpress admin panel (this is a fragment of a plugin):<br />
<code>   // setup Javascript redirect<br />
     $location='/wp/csv-output/?year='.$year.'&amp;month='.$month;<br />
 ?&gt;<br />
 &lt;script&gt;<br />
 function addListener(element, event, listener, bubble) {<br />
  if(element.addEventListener) {<br />
    if(typeof(bubble) == "undefined") bubble = false;<br />
    element.addEventListener(event, listener, bubble);<br />
  } else if(this.attachEvent) {<br />
    element.attachEvent("on" + event, listener);<br />
  }<br />
 }<br />
 addListener(this, "load", function() { window.location="&lt;?php echo $location ?&gt;" });<br />
 addListener(document, "load", function() { window.location="&lt;?php echo $location ?&gt;" });<br />
 &lt;/script&gt;</code><br />
And in my CSV page (again, just a fragment):<br />
<code>   ob_end_clean();<br />
   header("Content-type: application/csv");<br />
   header("Content-Disposition: attachment; filename=contact_data_$year_$month.csv");<br />
   header("Pragma: no-cache");<br />
   header("Expires: 0");</code><br />
I found the javascript code <a href="http://answers.google.com/answers/threadview?id=510976">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://beutelevision.com/blog2/2010/03/19/redirect-from-within-wordpress-admi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Result of expression &#8216;document.forms[0].submit&#8217; [[object HTMLInputElement]] is not a function.</title>
		<link>http://beutelevision.com/blog2/2009/09/15/result-of-expression-document-forms0-submit-object-htmlinputelement-is-not-a-function/</link>
		<comments>http://beutelevision.com/blog2/2009/09/15/result-of-expression-document-forms0-submit-object-htmlinputelement-is-not-a-function/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 21:34:48 +0000</pubDate>
		<dc:creator>Thomas Beutel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://beutelevision.com/blog2/2009/09/15/result-of-expression-document-forms0-submit-object-htmlinputelement-is-not-a-function/</guid>
		<description><![CDATA[I was trying to add a small delay into my form submission like so:
&#60;form ... onsubmit="setTimeout('document.forms[0].submit()',2000);return false;"&#62;
but everytime I tried it, I got the following error:
Result of expression 'document.forms[0].submit' [[object HTMLInputElement]] is not a function.
This one had me stumped, until I realized what it was telling me&#8230; that my submit button was named &#8220;submit&#8221;.
&#60;input type="submit" [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to add a small delay into my form submission like so:</p>
<p><code>&lt;form ... onsubmit="setTimeout('document.forms[0].submit()',2000);return false;"&gt;</code></p>
<p>but everytime I tried it, I got the following error:</p>
<p><code>Result of expression 'document.forms[0].submit' [[object HTMLInputElement]] is not a function.</code></p>
<p>This one had me stumped, until I realized what it was telling me&#8230; that my submit button was named &#8220;submit&#8221;.</p>
<p><code>&lt;input type="submit" name="submit" id="Button1" /&gt;</code></p>
<p>I changed the name of the submit button and the problem went away.</p>
<p><code>&lt;input type="submit" name="button1" id="Button1" /&gt;</code></p>
<p>Basically, Javascript provides a &#8220;convenience&#8221; by adding the names of the form inputs as children of the form. But this then clashes with preset function names, like the submit() function.</p>
]]></content:encoded>
			<wfw:commentRss>http://beutelevision.com/blog2/2009/09/15/result-of-expression-document-forms0-submit-object-htmlinputelement-is-not-a-function/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

