<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: onblur code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 21:58:02 GMT</pubDate>
    <description>DZone Snippets: onblur code</description>
    <item>
      <title>using Event.observe for when a page loads</title>
      <link>http://snippets.dzone.com/posts/show/3025</link>
      <description>I just prefer this implementation as opposed to window.onload.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Event.observe( window, 'load', function() {&lt;br /&gt;  // Put the Javascript that needs to happen when the page&lt;br /&gt;  // loads here&lt;br /&gt;} );&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For example, here's a way to make most of your input fields and all of your textareas have a different class when they're selected.  Useful if you want to style them differently with CSS.&lt;br /&gt;&lt;code&gt;Event.observe( window, 'load', function() {&lt;br /&gt;  var inputs = document.getElementsByTagName( 'input' );&lt;br /&gt;  var textareas = document.getElementsByTagName( 'textarea' );&lt;br /&gt;&lt;br /&gt;  for ( var i=0; i&lt;inputs.length; i++ ) {&lt;br /&gt;    type = inputs[i].type;&lt;br /&gt;&lt;br /&gt;    if (&lt;br /&gt;      ( type == 'button' || type == 'reset' ||&lt;br /&gt;      type == 'password' || type == 'text' ||&lt;br /&gt;      type == 'submit' ) &amp;&amp;&lt;br /&gt;      ( inputs[i].onfocus == '' ||&lt;br /&gt;      !inputs[i].onfocus )&lt;br /&gt;    ) {&lt;br /&gt;      inputs[i].onfocus = function() {&lt;br /&gt;        this.className = 'selected';&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      inputs[i].onblur = function() {&lt;br /&gt;        this.className = '';&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  for ( var i=0; i&lt;textareas.length; i++ ) {&lt;br /&gt;    if ( textareas[i].onfocus == '' || !textareas[i].onfocus ) {&lt;br /&gt;      textareas[i].onclick = function() {&lt;br /&gt;        this.className = 'selected';&lt;br /&gt;      }&lt;br /&gt;      textareas[i].onblur = function() {&lt;br /&gt;        this.className = '';&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;} );&lt;/code&gt;</description>
      <pubDate>Mon, 20 Nov 2006 20:47:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3025</guid>
      <author>moneypenny ()</author>
    </item>
  </channel>
</rss>
