Ok! So I have this survey project I''m working on where there are a list of questions but only one shows up at a time. That part''s easy. And, it is fully functional as we speak (and I think even ''live'') however..... My boss wants to be able to have the survey go to the next question when a user selects an answer. This part is easy.. except..... IE doesn''t fire the onChange event until the radio button group has lost focus. So if you just rely on the onChange event, the user has to make 2 clicks (in firefox, the onchange fires when you change the which option is selected) so, I thought.. I''ll just make it so when the option is focused, I immediately blur it so IE fires the onchange event. This works! Unfortunately, it breaks keyboard access to the form. Troublesome. So, I thought.. how about just making it so it fires onclick! Well, the problem with that is that in both IE and Firefox, when you use the keyboard to change which option is selected, it fires the onclick event! So far, I haven''t been able to differentiate this particular event between a ''real'' click and a keyboard-initiated onclick event (in either browser). I''ve sorta given up, and my boss went with the ''easy clicking for mouse users'' option and said ''screw accessibility'', and I pretty much agree with him.. but there''s gotta be some way to do this :) So here''s my question... anyone know how? What events should I listen for? What do I need to check in those events to tell if I''m being triggered by someone actually clicking with their mouse, or using the keyboard to select the answer. When all is said and done, I''m going to post a howto about this up on the web, as I''m sure stuff like this comes up from time to time... if nothing else I think it might be useful to someone.. hehe Thanks! -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
You could set a variable onmouseover, and when onclick is fired check for that variable to make sure they moused over the item first. Of course, you''d then also have to clear the variable onmouseout to make sure they didn''t just keep the mouse moving. Why do you care to differentiate between a click and a keyboard selection? Either way, they selected it. Greg
If all else fails, setup a 100ms periodic timer event handler. Loop thru the radio buttons, and you can decide when to move on from there. Sam
Prototype already has an observer for this. Form.Element.Observer I think. It uses a time based periodical check for a changed value so it doesn''t rely on events. On 01/07/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote:> If all else fails, setup a 100ms periodic timer event handler. Loop thru > the radio buttons, and you can decide when to move on from there. > > Sam > > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Andrew Tetlaw htp://tetlaw.id.au
Andrew Martinez (RIT Student)
2006-Jul-01 17:56 UTC
RE: javascript woes with radio button groups
You can tell if the mouse or the keyboard changed the radio button. Inspect which key has been pressed, if any, of if the left mouse button was clicked. Reference: http://www.quirksmode.org/js/events_properties.html In addition, instead of putting the event handler on the radio group put it on the individual radio buttons. I am sure this fixes all of your problems. ********************************* Andrew Martinez (apm9733-H6Ufl4FQnQQ@public.gmane.org) *********************************> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs- > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Andrew Tetlaw > Sent: Friday, June 30, 2006 9:15 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] javascript woes with radio button groups > > Prototype already has an observer for this. Form.Element.Observer I > think. It uses a time based periodical check for a changed value so it > doesn''t rely on events. > > On 01/07/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote: > > If all else fails, setup a 100ms periodic timer event handler. Loop > thru > > the radio buttons, and you can decide when to move on from there. > > > > Sam > > > > > > > > > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > -- > Andrew Tetlaw > htp://tetlaw.id.au > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Two comments: 1. If you''re navigating immediately on click, you''re already not really accessible to those with possible motor difficulties. (Accessibility doesn''t just mean visual impairments and text browsers!) 2. The functionality you''re describing isn''t really that of a radio button... it''s of a button that *looks* like a radio button. why not just use the <button> tag, imbed an image of a radio button, and style the whole thing to look like a regular radio button. Allows keyboard navigation! TAG On Jun 30, 2006, at 3:55 PM, Jeremy Kitchen wrote:> Ok! So I have this survey project I''m working on where there are a > list of > questions but only one shows up at a time. > > That part''s easy. And, it is fully functional as we speak (and I > think even > ''live'') however..... > > My boss wants to be able to have the survey go to the next question > when a > user selects an answer. This part is easy.. except..... > > IE doesn''t fire the onChange event until the radio button group has > lost > focus. So if you just rely on the onChange event, the user has to > make 2 > clicks (in firefox, the onchange fires when you change the which > option is > selected) > > so, I thought.. I''ll just make it so when the option is focused, I > immediately > blur it so IE fires the onchange event. This works! > Unfortunately, it > breaks keyboard access to the form. Troublesome. > > So, I thought.. how about just making it so it fires onclick! > Well, the > problem with that is that in both IE and Firefox, when you use the > keyboard > to change which option is selected, it fires the onclick event! So > far, I > haven''t been able to differentiate this particular event between a > ''real'' > click and a keyboard-initiated onclick event (in either browser). > > I''ve sorta given up, and my boss went with the ''easy clicking for > mouse users'' > option and said ''screw accessibility'', and I pretty much agree with > him.. but > there''s gotta be some way to do this :) > > So here''s my question... anyone know how? What events should I > listen for? > What do I need to check in those events to tell if I''m being > triggered by > someone actually clicking with their mouse, or using the keyboard > to select > the answer. > > When all is said and done, I''m going to post a howto about this up > on the web, > as I''m sure stuff like this comes up from time to time... if > nothing else I > think it might be useful to someone.. hehe > > Thanks! > > -Jeremy > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On Friday 30 June 2006 15:02, Gregory Hill wrote:> You could set a variable onmouseover, and when onclick is fired check > for that variable to make sure they moused over the item first. Of > course, you''d then also have to clear the variable onmouseout to make > sure they didn''t just keep the mouse moving.hmm. Not a bad idea, I''ll think about that :)> Why do you care to differentiate between a click and a keyboard > selection? Either way, they selected it.Because if they clicked it, they go to the next question.. but if they''re just using their keyboard to cycle through the options, I don''t want to :) -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On Saturday 01 July 2006 10:56, Andrew Martinez (RIT Student) wrote:> You can tell if the mouse or the keyboard changed the radio button. Inspect > which key has been pressed, if any, of if the left mouse button was > clicked. Reference: http://www.quirksmode.org/js/events_properties.html > > > In addition, instead of putting the event handler on the radio group put it > on the individual radio buttons. I am sure this fixes all of your problems.actually, when the onclick event is fired, it registers that it was a left click, and keyCode is undefined *grumble* sometimes I hate javascript... :P -Jeremy -- Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org http://www.pirate-party.us/ -- defend your rights _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs