So, I want to blur an input field when it is focused. I can easily add onfocus="this.blur()" to the html for the input field(s) that require it, but I''ve been trying to wean myself off of inline function calls little-by-little as I learn more about the prototype.js Event.observe() and related behavior. But, I haven''t been able to use Event.observe to fire a function on a focus event. I''ve tried to do things like Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the alert doesn''t happen. Is there something I''m missing? -- Dave -- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 16, 8:45 am, Colin Mollenhour <eliteii...-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote:> Will the readonly attribute not work? > <input type="text" readonly /> > Or in JS, I think you can do element.readonly="readonly" but I''m not > sure if that is the correct way offhand.It isn''t. The W3C DOM 2 HTML spec defines an HTMLInputElement interface with a "readOnly" attribute that is a boolean[1]. So: element.readOnly = true; 1. <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-88461592 > -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Will the readonly attribute not work? <input type="text" readonly /> Or in JS, I think you can do element.readonly="readonly" but I''m not sure if that is the correct way offhand. I don''t know why your focus event isn''t working, post more code (use pastie for large quantities) or a minimalistic test page if necessary. Colin David Dashifen Kees wrote:> So, I want to blur an input field when it is focused. I can easily add > onfocus="this.blur()" to the html for the input field(s) that require > it, but I''ve been trying to wean myself off of inline function calls > little-by-little as I learn more about the prototype.js Event.observe() > and related behavior. But, I haven''t been able to use Event.observe to > fire a function on a focus event. I''ve tried to do things like > Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the > alert doesn''t happen. Is there something I''m missing? > > -- Dave -- > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Wow. Pastie rocks: http://pastie.caboo.se/47296 So, you can see in that code on line #4 an attempt to force the counter to observe focus events. Currently, it''s just an anonymous call to the alert("hi") function but it never fires. I left the CSS out of it, but suffice it to say that the background positioning is used to control the look of the div.button elements so that they have an off, over, and pressed states like a button. Using them provides the basic functionality of a numeric counting widget like you can find in various incarnations (e.g., flash, python, etc.) but is lacking for web sites. Not sure if I really need the code to work; it was just an exercise. So, the needs are this: (1) to determine why, in the code linked above, the focus action is never fired for the counter elements and (2) once the event is firing, change it from an alert event to simply blur the focused field. Thanks for taking a peak! -- Dash -- Colin Mollenhour wrote:> Will the readonly attribute not work? > <input type="text" readonly /> > Or in JS, I think you can do element.readonly="readonly" but I''m not > sure if that is the correct way offhand. > > I don''t know why your focus event isn''t working, post more code (use > pastie for large quantities) or a minimalistic test page if necessary. > > Colin > > David Dashifen Kees wrote: > >> So, I want to blur an input field when it is focused. I can easily add >> onfocus="this.blur()" to the html for the input field(s) that require >> it, but I''ve been trying to wean myself off of inline function calls >> little-by-little as I learn more about the prototype.js Event.observe() >> and related behavior. But, I haven''t been able to use Event.observe to >> fire a function on a focus event. I''ve tried to do things like >> Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the >> alert doesn''t happen. Is there something I''m missing? >> >> -- Dave -- >> >> >> >> > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
You''re selector is selecting the div instead of the input box, so therefore your "focus" observer is being attached to the div (which will never fire a focus event) instead of the input. You could change the first line to look like the following and it will work: var input = counter.getElementsByTagName(''input'')[0]; input.observe("focus", function(event) { Event.element(event).blur(); }); Not sure what you''re trying to do with with attaching all those mouse events. -justin On 3/15/07, David Dashifen Kees <dashifen-NT0ononE2K1Wk0Htik3J/w@public.gmane.org> wrote:> > Wow. Pastie rocks: http://pastie.caboo.se/47296 > > So, you can see in that code on line #4 an attempt to force the counter to > observe focus events. Currently, it''s just an anonymous call to the > alert("hi") function but it never fires. I left the CSS out of it, but > suffice it to say that the background positioning is used to control the > look of the div.button elements so that they have an off, over, and pressed > states like a button. Using them provides the basic functionality of a > numeric counting widget like you can find in various incarnations (e.g., > flash, python, etc.) but is lacking for web sites. Not sure if I really > need the code to work; it was just an exercise. > > So, the needs are this: (1) to determine why, in the code linked above, > the focus action is never fired for the counter elements and (2) once the > event is firing, change it from an alert event to simply blur the focused > field. > > Thanks for taking a peak! > > -- Dash -- > > > Colin Mollenhour wrote: > Will the readonly attribute not work? > <input type="text" readonly /> > Or in JS, I think you can do element.readonly="readonly" but I''m not > sure if that is the correct way offhand. > > I don''t know why your focus event isn''t working, post more code (use > pastie for large quantities) or a minimalistic test page if necessary. > > Colin > > David Dashifen Kees wrote: > > > So, I want to blur an input field when it is focused. I can easily add > onfocus="this.blur()" to the html for the input field(s) that require > it, but I''ve been trying to wean myself off of inline function calls > little-by-little as I learn more about the prototype.js Event.observe() > and related behavior. But, I haven''t been able to use Event.observe to > fire a function on a focus event. I''ve tried to do things like > Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the > alert doesn''t happen. Is there something I''m missing? > > -- Dave -- > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> I''m sure you''ll be smacking your forehead against the desk on this one :)<br> You are trying to observe focus of a div. Divs do not support focus. To observe the input element change line 4 of your pastie to:<br> counter.down(''input.counter'').observe("focus", function() { alert("hi") });<br> or something similar...<br> <br> Cheers,<br> Colin<br> <br> <br> David Dashifen Kees wrote: <blockquote cite="mid:45F9FEED.609-NT0ononE2K1Wk0Htik3J/w@public.gmane.org" type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> Wow. Pastie rocks: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://pastie.caboo.se/47296">http://pastie.caboo.se/47296</a><br> <br> So, you can see in that code on line #4 an attempt to force the counter to observe focus events. Currently, it''s just an anonymous call to the alert("hi") function but it never fires. I left the CSS out of it, but suffice it to say that the background positioning is used to control the look of the div.button elements so that they have an off, over, and pressed states like a button. Using them provides the basic functionality of a numeric counting widget like you can find in various incarnations (e.g., flash, python, etc.) but is lacking for web sites. Not sure if I really need the code to work; it was just an exercise.<br> <br> So, the needs are this: (1) to determine why, in the code linked above, the focus action is never fired for the counter elements and (2) once the event is firing, change it from an alert event to simply blur the focused field. <br> <br> Thanks for taking a peak!<br> <br> -- Dash --<br> <br> Colin Mollenhour wrote: <blockquote cite="mid45F9CC94.4020301-NPSFNn/7+NYVo650/ln6uw@public.gmane.org" type="cite"> <pre wrap="">Will the readonly attribute not work? <input type="text" readonly /> Or in JS, I think you can do element.readonly="readonly" but I''m not sure if that is the correct way offhand. I don''t know why your focus event isn''t working, post more code (use pastie for large quantities) or a minimalistic test page if necessary. Colin David Dashifen Kees wrote: </pre> <blockquote type="cite"> <pre wrap="">So, I want to blur an input field when it is focused. I can easily add onfocus="this.blur()" to the html for the input field(s) that require it, but I''ve been trying to wean myself off of inline function calls little-by-little as I learn more about the prototype.js Event.observe() and related behavior. But, I haven''t been able to use Event.observe to fire a function on a focus event. I''ve tried to do things like Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the alert doesn''t happen. Is there something I''m missing? -- Dave -- </pre> <pre wrap=""> </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> <br> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Forgot part deux..<br> counter.down(''input.counter'').observe("focus", function(event){ Event.element(event).blur(); });<br> although I tested in IE6 and it seems the elements aren''t extended so I had to do this:<br> $($(counter).down(''input.counter'')).observe("focus", function(event){ Event.element(event).blur(); });<br> Now what the hell is that? Surely prototype can extend elements itself somewhere along the line. Wrapping each element in $() just looks silly. What good is chaining if you can''t do it properly?<br> <br> Colin<br> <br> David Dashifen Kees wrote: <blockquote cite="mid:45F9FEED.609-NT0ononE2K1Wk0Htik3J/w@public.gmane.org" type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> Wow. Pastie rocks: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://pastie.caboo.se/47296">http://pastie.caboo.se/47296</a><br> <br> So, you can see in that code on line #4 an attempt to force the counter to observe focus events. Currently, it''s just an anonymous call to the alert("hi") function but it never fires. I left the CSS out of it, but suffice it to say that the background positioning is used to control the look of the div.button elements so that they have an off, over, and pressed states like a button. Using them provides the basic functionality of a numeric counting widget like you can find in various incarnations (e.g., flash, python, etc.) but is lacking for web sites. Not sure if I really need the code to work; it was just an exercise.<br> <br> So, the needs are this: (1) to determine why, in the code linked above, the focus action is never fired for the counter elements and (2) once the event is firing, change it from an alert event to simply blur the focused field. <br> <br> Thanks for taking a peak!<br> <br> -- Dash --<br> <br> Colin Mollenhour wrote: <blockquote cite="mid45F9CC94.4020301-NPSFNn/7+NYVo650/ln6uw@public.gmane.org" type="cite"> <pre wrap="">Will the readonly attribute not work? <input type="text" readonly /> Or in JS, I think you can do element.readonly="readonly" but I''m not sure if that is the correct way offhand. I don''t know why your focus event isn''t working, post more code (use pastie for large quantities) or a minimalistic test page if necessary. Colin David Dashifen Kees wrote: </pre> <blockquote type="cite"> <pre wrap="">So, I want to blur an input field when it is focused. I can easily add onfocus="this.blur()" to the html for the input field(s) that require it, but I''ve been trying to wean myself off of inline function calls little-by-little as I learn more about the prototype.js Event.observe() and related behavior. But, I haven''t been able to use Event.observe to fire a function on a focus event. I''ve tried to do things like Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the alert doesn''t happen. Is there something I''m missing? -- Dave -- </pre> <pre wrap=""> </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> <br> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> The extend problem was fixed in 1.5.1_rc2, so that''s cool. You can now ignore the latter part of that last message.<br> <br> Colin<br> <br> Colin Mollenhour wrote: <blockquote cite="mid:45FA1584.8010907-NPSFNn/7+NYVo650/ln6uw@public.gmane.org" type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> Forgot part deux..<br> counter.down(''input.counter'').observe("focus", function(event){ Event.element(event).blur(); });<br> although I tested in IE6 and it seems the elements aren''t extended so I had to do this:<br> $($(counter).down(''input.counter'')).observe("focus", function(event){ Event.element(event).blur(); });<br> Now what the hell is that? Surely prototype can extend elements itself somewhere along the line. Wrapping each element in $() just looks silly. What good is chaining if you can''t do it properly?<br> <br> Colin<br> <br> David Dashifen Kees wrote: <blockquote cite="mid:45F9FEED.609-NT0ononE2K1Wk0Htik3J/w@public.gmane.org" type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> Wow. Pastie rocks: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://pastie.caboo.se/47296">http://pastie.caboo.se/47296</a><br> <br> So, you can see in that code on line #4 an attempt to force the counter to observe focus events. Currently, it''s just an anonymous call to the alert("hi") function but it never fires. I left the CSS out of it, but suffice it to say that the background positioning is used to control the look of the div.button elements so that they have an off, over, and pressed states like a button. Using them provides the basic functionality of a numeric counting widget like you can find in various incarnations (e.g., flash, python, etc.) but is lacking for web sites. Not sure if I really need the code to work; it was just an exercise.<br> <br> So, the needs are this: (1) to determine why, in the code linked above, the focus action is never fired for the counter elements and (2) once the event is firing, change it from an alert event to simply blur the focused field. <br> <br> Thanks for taking a peak!<br> <br> -- Dash --<br> <br> Colin Mollenhour wrote: <blockquote cite="mid45F9CC94.4020301-NPSFNn/7+NYVo650/ln6uw@public.gmane.org" type="cite"> <pre wrap="">Will the readonly attribute not work? <input type="text" readonly /> Or in JS, I think you can do element.readonly="readonly" but I''m not sure if that is the correct way offhand. I don''t know why your focus event isn''t working, post more code (use pastie for large quantities) or a minimalistic test page if necessary. Colin David Dashifen Kees wrote: </pre> <blockquote type="cite"> <pre wrap="">So, I want to blur an input field when it is focused. I can easily add onfocus="this.blur()" to the html for the input field(s) that require it, but I''ve been trying to wean myself off of inline function calls little-by-little as I learn more about the prototype.js Event.observe() and related behavior. But, I haven''t been able to use Event.observe to fire a function on a focus event. I''ve tried to do things like Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the alert doesn''t happen. Is there something I''m missing? -- Dave -- </pre> <pre wrap=""> </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> <br> </blockquote> <br> <br> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
Damnit. You''d think that in 2ish hours of random hacking to figure out what''s going on prior to asking for help, I''d have seen that. Sigh. Thanks! -- Dash -- Colin Mollenhour wrote:> I''m sure you''ll be smacking your forehead against the desk on this one :) > You are trying to observe focus of a div. Divs do not support focus. To observe > the input element change line 4 of your pastie to: > counter.down(''input.counter'').observe("focus", function() { alert("hi") }); > or something similar... > > Cheers, > Colin > > > David Dashifen Kees wrote: > > Wow. Pastie rocks: http://pastie.caboo.se/47296 > > > > So, you can see in that code on line #4 an attempt to force the counter to > > observe focus events. Currently, it''s just an anonymous call to the > > alert("hi") function but it never fires. I left the CSS out of it, but > > suffice it to say that the background positioning is used to control the look > > of the div.button elements so that they have an off, over, and pressed states > > like a button. Using them provides the basic functionality of a numeric > > counting widget like you can find in various incarnations (e.g., flash, > > python, etc.) but is lacking for web sites. Not sure if I really need the > > code to work; it was just an exercise. > > > > So, the needs are this: (1) to determine why, in the code linked above, the > > focus action is never fired for the counter elements and (2) once the event is > > firing, change it from an alert event to simply blur the focused field. > > > > Thanks for taking a peak! > > > > -- Dash -- > > > > Colin Mollenhour wrote: > >> Will the readonly attribute not work? > >> <input type="text" readonly /> > >> Or in JS, I think you can do element.readonly="readonly" but I''m not > >> sure if that is the correct way offhand. > >> > >> I don''t know why your focus event isn''t working, post more code (use > >> pastie for large quantities) or a minimalistic test page if necessary. > >> > >> Colin > >> > >> David Dashifen Kees wrote: > >> > >>> So, I want to blur an input field when it is focused. I can easily add > >>> onfocus="this.blur()" to the html for the input field(s) that require > >>> it, but I''ve been trying to wean myself off of inline function calls > >>> little-by-little as I learn more about the prototype.js Event.observe() > >>> and related behavior. But, I haven''t been able to use Event.observe to > >>> fire a function on a focus event. I''ve tried to do things like > >>> Event.observe($("blur_me"), "focus", function() { alert("hi") }) and the > >>> alert doesn''t happen. Is there something I''m missing? > >>> > >>> -- Dave -- > >>> > >>> > >>> > >>> > >> > >> > >> > >> > >> > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---