I have this code to capture all clicks on the document: document.observe("click", function(this) { alert(this.id); Its throwing an error saying missing formal parameter, pointing at the this reference in my function. I know i must be doing something wrong. What i want to do is alert out the id ( if any) on whatever has been clicked on. Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
"this" is a keyword, it can not be used as a function argument. Choose any other valid name and you''ll be just fine. - kangax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
aha of course...thanks....unfortunately it doesnt seem to work....i get an alert back every time i click but its always undefined....i''ve posted it in the context of the rest of my code just in case something else might be causing the problem....the bit directly concerned is at the bottom document.observe("dom:loaded", function() { var forms = $$(''select''); var container = $(''container''); forms.each(function(select, index) { select.hide(); var ul = new Element(''ul'', { id: ''list_'' + (index +1) + ''_body''}); var options = select.select("option"); options.each(function(option) { var li = new Element(''li''); var anchor = new Element(''a'', {class: ''listelement''}).update(option.innerHTML); li.appendChild(anchor); ul.appendChild(li); container.appendChild(ul); }); var aTag = new Element(''a'', { id: ''list_'' + (index +1), class: ''selectelement'', href:''#'' }).update(''select...''); container.appendChild(aTag); }) document.observe("click", function(itt) { alert(itt.innerHTML); }) }) On Jan 24, 11:29 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> "this" is a keyword, it can not be used as a function argument. Choose > any other valid name and you''ll be just fine. > > - kangax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Event handler (in this context) gets event object as a first argument. This event object does NOT have innerHTML property. Since you are using 1.6, a preferred way to access element is via "this", event.element() or event.target. document.observe(''click'', function(event) { alert(event.element().innerHTML); // or alert(this.innerHTML); ... }) - kangax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Got you i understand that now...thanks! On Jan 25, 1:04 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Event handler (in this context) gets event object as a first > argument. > This event object does NOT have innerHTML property. > Since you are using 1.6, a preferred way to access element is via > "this", > event.element() or event.target. > > document.observe(''click'', function(event) { > alert(event.element().innerHTML); > // or > alert(this.innerHTML); > ... > > }) > > - kangax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---