Skip to main content

Radio button onchange+ajax

5 replies [Last post]
gabox01
Offline
Joined: 2007-04-22

Hi,

I have a SelectOneRadio:

When i click on the radio buttons, sometimes, the valuechangelistener won't get called. It takes one or two other click, to to get it called. The problem only exists with ajax+onchange.

Can you reproduce the problem?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Driscoll

I should say:

There is a workaround.

If you're on IE, then register an onfocus function that periodically
removes the focus. Eww.

We may have to do this for JSF. I've been thinking about it.

Jim

On 7/27/09 10:20 AM, Jim Driscoll wrote:
> What browser are you using? I bet it's IE. Further, I bet it works on
> Firefox, doesn't it? And Safari, too, right? (You are testing on more
> than one browser, right?)
>
> Is what you're seeing related to the buttons losing focus? I.e., is the
> event only being fired when the focus is lost?
>
> I IE only fires the onchange event when you surrender focus on the tag -
> which is why you're only seeing it sometimes.
>
> See here:
>
> http://msdn.microsoft.com/en-us/library/ms536912%28VS.85%29.aspx
>
> From that page:
>
> This event is fired when the contents are committed and not while the
> value is changing. For example, on a text box, this event is not fired
> while the user is typing, but rather when the user commits the change by
> leaving the text box that has focus. In addition, this event is executed
> before the code specified by onblur when the control is also losing the
> focus.
>
> The onchange event does not fire when the selected option of the select
> object is changed programatically.
>
> --------- End Quote -----------
>
> One more reason to hate Microsoft. No other browser does this, AFAIK.
>
> No, I don't know of a workaround. If anyone does... I'd love to hear it.
>
> When reporting JavaScript client problems *always* say which browser
> you're seeing the problem in - the default is of course IE, but hey,
> Safari has bugs too.
>
> Jim
>
> On 7/27/09 12:54 AM, webtier@javadesktop.org wrote:
>> Hi,
>>
>> I have a SelectOneRadio:
>>
>> >> value="#{testBean.goods}" onchange="jsf.ajax.request(this, event,
>> {execute: 'sor', render: 'pg1'}); return false;">
>>
>>
>>

>>
>> When i click on the radio buttons, sometimes, the valuechangelistener
>> won't get called. It takes one or two other click, to to get it
>> called. The problem only exists with ajax+onchange.
>>
>> Can you reproduce the problem?
>> [Message sent by forum member 'gabox01' (gabox01)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=357632
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

jtkehoe
Offline
Joined: 2010-03-12

I know this is an old post, but just in case someone else stumbles across it like I did, there is an easy work around to get the selectOneRadio onchange event to fire in IE. I found this on a different forum and it worked for me (also still works in Firefox).

Add this to the control:
onclick="this.blur()"

Jim Driscoll

What browser are you using? I bet it's IE. Further, I bet it works on
Firefox, doesn't it? And Safari, too, right? (You are testing on more
than one browser, right?)

Is what you're seeing related to the buttons losing focus? I.e., is the
event only being fired when the focus is lost?

I IE only fires the onchange event when you surrender focus on the tag -
which is why you're only seeing it sometimes.

See here:

http://msdn.microsoft.com/en-us/library/ms536912%28VS.85%29.aspx

From that page:

This event is fired when the contents are committed and not while
the value is changing. For example, on a text box, this event is not
fired while the user is typing, but rather when the user commits the
change by leaving the text box that has focus. In addition, this event
is executed before the code specified by onblur when the control is also
losing the focus.

The onchange event does not fire when the selected option of the
select object is changed programatically.

--------- End Quote -----------

One more reason to hate Microsoft. No other browser does this, AFAIK.

No, I don't know of a workaround. If anyone does... I'd love to hear it.

When reporting JavaScript client problems *always* say which browser
you're seeing the problem in - the default is of course IE, but hey,
Safari has bugs too.

Jim

On 7/27/09 12:54 AM, webtier@javadesktop.org wrote:
> Hi,
>
> I have a SelectOneRadio:
>
>
>
>
>

>
> When i click on the radio buttons, sometimes, the valuechangelistener won't get called. It takes one or two other click, to to get it called. The problem only exists with ajax+onchange.
>
> Can you reproduce the problem?
> [Message sent by forum member 'gabox01' (gabox01)]
>
> http://forums.java.net/jive/thread.jspa?messageID=357632
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

gabox01
Offline
Joined: 2007-04-22

You are right, the problem has nothing to do with JSF.
Thanks for the explanation.

rogerk
Offline
Joined: 2004-05-06

Can you run this through firebug (or whatever javascript debugging tool you use) to see if the ajax requests are happening?