Matthew Marksbury
2008-Feb-13 19:10 UTC
Event.Observe on Radio Button in Radio Button List
My HTML: ------------------------------ <form id="someForm"> <input type="radio" id="myRadio_1" name="myRadio" /> <label for="myRadio_1">Radio 1</label> <input type="radio" id="myRadio_2" name="myRadio" /> <label for="myRadio_2">Radio 1</label> <input type="radio" id="myRadio_3" name="myRadio" /> <label for="myRadio_3">Radio 1</label> </form> My Javascript: --------------------------------- Event.observe(''myRadio_3'', ''click'', function() {alert(''some logic goes here'');}); My Issue: --------------------------------- I am having an issue with an event getting attached to an entire radio button list, and not a single radio button when using Event.observe. Note that using Event.observe will create a click event handler for each radio button in the list, whereas, manually attaching the onclick handler within the HTML itself (i.e. onclick="alert(''some logic goes here);" ), functions correctly. Is this an issue with Prototype, or my usage? Any suggestions? --~--~---------~--~----~------------~-------~--~----~ 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 Feb 13, 2008 2:10 PM, Matthew Marksbury <mmarksbury-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > My HTML: > ------------------------------ > <form id="someForm"> > <input type="radio" id="myRadio_1" name="myRadio" /> > <label for="myRadio_1">Radio 1</label> > > <input type="radio" id="myRadio_2" name="myRadio" /> > <label for="myRadio_2">Radio 1</label> > > <input type="radio" id="myRadio_3" name="myRadio" /> > <label for="myRadio_3">Radio 1</label> > </form> > > My Javascript: > --------------------------------- > Event.observe(''myRadio_3'', ''click'', function() {alert(''some logic goes > here'');});if you want to attach the observer to each one of the radio buttons, one way is to get a list of them using $$(), or in 1.6 select(); something like this, $(''someForm'').select(input[type="radio"]).each(function(curInput) { Event.observe(curInput, ''click'', function() {alert(''some logic goes here'');}); }); -nathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Walter Lee Davis
2008-Feb-13 19:47 UTC
Re: Event.Observe on Radio Button in Radio Button List
I am not seeing the error you describe here. It only triggers if I click on the third radio, never when I click on the other two. Is that in fact what you wanted? What browser are you in when you get the alert from clicking any of the three radios? Walter On Feb 13, 2008, at 2:10 PM, Matthew Marksbury wrote:> I am having an issue with an event getting attached to an entire radio > button list, and not a single radio button when using Event.observe. > > Note that using Event.observe will create a click event handler for > each radio button in the list, whereas, manually attaching the onclick > handler within the HTML itself (i.e. onclick="alert(''some logic goes > here);" ), functions correctly.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''m seeing "normal" behavior, just like Walter described. Which prototype version and browser are you seeing this with? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matthew Marksbury
2008-Feb-13 21:28 UTC
Re: Event.Observe on Radio Button in Radio Button List
1.6 on firefox. On Feb 13, 12:03 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m seeing "normal" behavior, just like Walter described. Which > prototype version and browser are you seeing this with?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---