<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1037364" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1037364</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214401</link>
    <description> &lt;p&gt;Okay, that seems to work, but how do I tell it what function to run? Before I had:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;objblurHandler.eventCallBack = function() {&lt;br /&gt;	validate(&amp;#039;residence&amp;#039;);&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&#039; &lt;/p&gt;
&lt;p&gt;but I can&#039;t do that anymore. I need to pass the value to the validate() function...&lt;/p&gt;
 </description>
     <pubDate>Thu, 01 Feb 2007 19:45:48 +0000</pubDate>
 <dc:creator>Megan</dc:creator>
 <guid isPermaLink="false">comment 1214401 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214400</link>
    <description> &lt;p&gt;Looking at the code of that library, this should also work:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;var objloadHandler = new eventHandler();&lt;br /&gt;var objblurHandler = new eventHandler();&lt;br /&gt;&lt;br /&gt;objblurHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; alert(&amp;#039;Our sublair is under attack!&amp;#039;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;objloadHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(&amp;#039;name&amp;#039;, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(&amp;#039;residence&amp;#039;, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(&amp;#039;year&amp;#039;, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(&amp;#039;email&amp;#039;, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(&amp;#039;photopath&amp;#039;, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;objloadHandler.addEventHandler(window,&amp;#039;load&amp;#039;, objloadHandler.eventCallBack);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Cuts doon on the code a bit, eh?&lt;/p&gt;
&lt;p&gt;I haven&#039;t tested this, but it should work. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 01 Feb 2007 19:38:39 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1214400 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214399</link>
    <description> &lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;var objloadHandler = new eventHandler();&lt;br /&gt;var objblurHandler = new eventHandler();&lt;br /&gt;&lt;br /&gt;objblurHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; alert(&amp;#039;Our sublair is under attack!&amp;#039;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;objloadHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;residence&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;name&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;year&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;email&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;photopath&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;objloadHandler.addEventHandler(window,&amp;#039;load&amp;#039;, objloadHandler.eventCallBack);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Here&#039;s how you can re-use the same eventHandler object with multiple HTML elements. Sorry for the delay but I wanted to test this with an actual HTML form to see if it works. It seems fine.&lt;/p&gt;
&lt;p&gt;I suspect your code wasn&#039;t working because it was trying to add the handlers before the page loaded, don&#039;t worry about getting it wrong: events can cause headaches! Nothing works in sequence, so they&#039;re confusing to programmers who expect to see everything running line by line. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;My naming conventions (like prefixing everything with &#039;obj&#039; or &#039;str&#039;) come from my VB background. The first three letters always denote the type of variable (or object) being used. Feel free to change it to suit yourself, there are no comments because I wrote all this off the top of my head in a hurry. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 01 Feb 2007 19:31:33 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1214399 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214393</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;Megan wrote:&lt;/strong&gt; Oh, and one question: is it better to have a lot of separate .js files or to keep all my script in a few files?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Just seperate things logically as you see fit. Like I knew when creating &#039;event.js&#039; that I&#039;d need to plug it into lots of projects so I seperated it. It also does one thing (and hopefully does it well) so that made it a good thing to keep by itself too.&lt;/p&gt;
&lt;p&gt;There&#039;re no real rules for this, just make sure you&#039;re consistent. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Will look at your code now... What have you done to it?! &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/big.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 01 Feb 2007 17:46:27 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1214393 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214382</link>
    <description> &lt;p&gt;Now I have this code, which allows me to use different event handlers and pass different functions. It still only works on the last makeEvent call:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;var onloadHandler = new eventHandler();&lt;br /&gt;var onblurHandler = new eventHandler();&lt;br /&gt;&lt;br /&gt;function makeEvent(element, event, func) {&lt;br /&gt;	onblurHandler.eventCallBack = function() {&lt;br /&gt;	&amp;nbsp; func(element); // testing to make sure it works&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	onloadHandler.eventCallBack = function() {&lt;br /&gt;	&amp;nbsp; onBlur = document.getElementById(element);&lt;br /&gt;	&amp;nbsp; onblurHandler.addEventHandler(element, event, onblurHandler.eventCallBack); // adds event to the function in the eventHandlers.js file&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;makeEvent(&amp;#039;name&amp;#039;, &amp;#039;blur&amp;#039;, validate);&lt;br /&gt;makeEvent(&amp;#039;residence&amp;#039;, &amp;#039;blur&amp;#039;, validate);&lt;br /&gt;makeEvent(&amp;#039;year&amp;#039;, &amp;#039;blur&amp;#039;, validate);&lt;br /&gt;makeEvent(&amp;#039;email&amp;#039;, &amp;#039;blur&amp;#039;, validate_email);&lt;br /&gt;makeEvent(&amp;#039;photopath&amp;#039;, &amp;#039;blur&amp;#039;, validate_photopath);&lt;br /&gt;&lt;br /&gt;onloadHandler.addEventHandler(window,&amp;#039;load&amp;#039;, onloadHandler.eventCallBack);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Oh, and one question: is it better to have a lot of separate .js files or to keep all my script in a few files?&lt;/p&gt;
 </description>
     <pubDate>Thu, 01 Feb 2007 15:10:32 +0000</pubDate>
 <dc:creator>Megan</dc:creator>
 <guid isPermaLink="false">comment 1214382 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214381</link>
    <description> &lt;p&gt;Yay, it works! No, what would be the best thing to do when I have 4 fields I need to validate? Three of them get the same function, one gets a different function. I&#039;ll see what I can do with that but help would be appreciated &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I tried wrapping the event creator part into a function and calling that for each field but it only works on the last one, so this isn&#039;t right:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;var onloadHandler = new eventHandler();&lt;br /&gt;var onblurHandler = new eventHandler();&lt;br /&gt;&lt;br /&gt;function makeBlurEvent(event) {&lt;br /&gt;	onblurHandler.eventCallBack = function() {&lt;br /&gt;	&amp;nbsp; validate(event); // testing to make sure it works&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	onloadHandler.eventCallBack = function() {&lt;br /&gt;	&amp;nbsp; onBlur = document.getElementById(event);&lt;br /&gt;	&amp;nbsp; onblurHandler.addEventHandler(event, &amp;#039;blur&amp;#039;, onblurHandler.eventCallBack); // adds event to the function in the eventHandlers.js file&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;makeBlurEvent(&amp;#039;name&amp;#039;);&lt;br /&gt;makeBlurEvent(&amp;#039;residence&amp;#039;);&lt;br /&gt;makeBlurEvent(&amp;#039;year&amp;#039;);&lt;br /&gt;makeBlurEvent(&amp;#039;email&amp;#039;);&lt;br /&gt;&lt;br /&gt;onloadHandler.addEventHandler(window,&amp;#039;load&amp;#039;, onloadHandler.eventCallBack);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Oh, and I changed your obj to on because the obj made it more confusing to me. That&#039;s another problem with all these samples - abbreviations in the variable and function names and no commenting make it much harder to understand.&lt;/p&gt;
 </description>
     <pubDate>Thu, 01 Feb 2007 14:39:07 +0000</pubDate>
 <dc:creator>Megan</dc:creator>
 <guid isPermaLink="false">comment 1214381 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214340</link>
    <description> &lt;p&gt;You should write a tutorial for the new site about this. I had a really hard time finding anything useful on a search.&lt;/p&gt;
 </description>
     <pubDate>Wed, 31 Jan 2007 21:13:53 +0000</pubDate>
 <dc:creator>Megan</dc:creator>
 <guid isPermaLink="false">comment 1214340 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214336</link>
    <description> &lt;p&gt;Well all you need to worry about are the first two blocks of code: the first goes in your HTML Head block. The second goes in a javascript file of your choice. Should work out of the box, then you can customise at your leisure! &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The rest of all that is just an explanation.&lt;/p&gt;
 </description>
     <pubDate>Wed, 31 Jan 2007 20:51:38 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1214336 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214334</link>
    <description> &lt;p&gt;Oooh, thanks for that sweetie! I think I might have to work on that tomorrow. Looks like a lot to do &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Wed, 31 Jan 2007 20:42:26 +0000</pubDate>
 <dc:creator>Megan</dc:creator>
 <guid isPermaLink="false">comment 1214334 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/avoiding-inline-event-handlers-javascript#comment-1214333</link>
    <description> &lt;p&gt;Well I found out how to do this a couple of years ago so have no idea where I learnt it! Probably from &lt;a href=&quot;http://www.quirksmode.org&quot; class=&quot;bb-url&quot;&gt;http://www.quirksmode.org&lt;/a&gt; that bloke knows what he&#039;s talking about.&lt;/p&gt;
&lt;p&gt;Attached is a very small Javascript library with just a couple of functions I use every time I want to get Javascript code hooked onto an HTML event.&lt;/p&gt;
&lt;p&gt;What you&#039;ll need to do is include that file into the html page code along with your own Javascript:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;amp;lt;script src=&amp;quot;event.js&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;amp;gt;&amp;amp;lt;/script&amp;amp;gt;&lt;br /&gt;&amp;amp;lt;script src=&amp;quot;yourcode.js&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;amp;gt;&amp;amp;lt;/script&amp;amp;gt;&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Ending up with something like this in your  declaration. In your yourcode.js file you should have some functions that will be associated with events, the library defines a function called eventCallBack for that purpose. The yourcode.js file should look something like:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;var objloadHandler = new eventHandler();&lt;br /&gt;var objblurHandler = new eventHandler();&lt;br /&gt;&lt;br /&gt;objblurHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; alert(&amp;#039;Our sublair is under attack!&amp;#039;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;objloadHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;residence&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;objloadHandler.addEventHandler(window,&amp;#039;load&amp;#039;, objloadHandler.eventCallBack);&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Note: the sublair thing is from a game called &lt;a href=&quot;http://www.s2games.com/savage/&quot; class=&quot;bb-url&quot;&gt;Savage&lt;/a&gt;. Play it, works on Linux and it&#039;s free (as in beer). &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt; Other than wanting to support a great game, it was the first thing that popped into my head.&lt;/p&gt;
&lt;p&gt;Back to the code: this seems a bit backwards, but the code is in this order so functions are always available when loading: preventing errors. This makes more sense when broken down:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;var objloadHandler = new eventHandler();&lt;br /&gt;var objblurHandler = new eventHandler();&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Firstly new event handler objects are created. These are defined in the library, one new object is required per event. They don&#039;t do anything at the moment as they haven&#039;t been hooked onto an event.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;objblurHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; alert(&amp;quot;Our sublair is under attack!&amp;quot;);&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Then the eventCallBack function is added to our new objblurHandler object. Note that it is just added at this point (well the correct term is overloaded, but am not about to explain that!), not called or used at all. In fact this is the last function that will be called, when the &#039;residence&#039; element blur event occurs.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;objloadHandler.eventCallBack = function() {&lt;br /&gt;&amp;nbsp; objBlur = document.getElementById(&amp;#039;residence&amp;#039;);&lt;br /&gt;&amp;nbsp; objblurHandler.addEventHandler(objBlur, &amp;#039;blur&amp;#039;, objblurHandler.eventCallBack);&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&#039;&lt;br /&gt;
Like the eventCallBack function added to objblurHandler an eventCallBack is added to the objloadHandler, to be triggered after the page has finished loading. The &#039;residence&#039; element cannot be accessed before the page has loaded, which is why this step is required.&lt;/p&gt;
&lt;p&gt;The code within this function tells the objblurHandler object that when/if the &#039;residence&#039; element blur event happens it should call the [incode]objblurHandler.eventCallBack[/incode] function.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;objloadHandler.addEventHandler(window,&amp;#039;load&amp;#039;, objloadHandler.eventCallBack);&lt;/code&gt;&#039;&lt;br /&gt;
Finally we tell the objloadHandler that when the page load event happens the [incode]objloadHandler.eventCallBack[/incode] function should be called. This does all the blur event stuff just discussed.&lt;/p&gt;
&lt;p&gt;Hope this makes sense, event handling isn&#039;t always the easiest of subjects. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Wed, 31 Jan 2007 20:33:27 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1214333 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
