Radio Button events

Hi,

I have observers for a group of radio buttons, an observe_field for each
radio button (I think its not possible to have one observe_field for a
group of radio buttons).

Now, the problem is that when I click on one radio button, all the
observers get trigerred, so the method which the observe_field calls
gets the wrong result. I just want that method to get the radio button
that is clicked, which seems quite obvious, no?

Any idea how to do this? Help would be greatly appreciated!

Thanks,

Aditya

Aditya R. wrote:

Hi,

I have observers for a group of radio buttons, an observe_field for each
radio button (I think its not possible to have one observe_field for a
group of radio buttons).

Now, the problem is that when I click on one radio button, all the
observers get trigerred, so the method which the observe_field calls
gets the wrong result. I just want that method to get the radio button
that is clicked, which seems quite obvious, no?

Any idea how to do this? Help would be greatly appreciated!

Thanks,

Aditya

I believe radio buttons all have same id/name. You can test the value
of the button group by:

$(‘common-radio-button-id’).value == ‘foo’

That should at least tell you whats selected.

Thanks for the reply. Unfortunately the radio buttons have different
id’s (though the same name). The ‘value’ is appended to the id, which
makes the id’s different for all the buttons. Which is why I need to
have a different observer for each button (since the observer takes the
id name).

Moreover, $(‘common-radio-button-id’).value doesn’t work. I get a parse
error, so probably that syntax is incorrect. Also, I don’t know if the
radio_button has a “value” method. I don’t see anything about it in the
Rails API.

Any other ideas?

I believe radio buttons all have same id/name. You can test the value
of the button group by:

$(‘common-radio-button-id’).value == ‘foo’

That should at least tell you whats selected.

Hi Aditya,

Aditya R. wrote:

(1) > (I think its not possible to have one

observe_field for a group of radio buttons).

(2) > Now, the problem is that when I click on one radio

button, all the observers get trigerred,

Given the observed behavior in (2), what makes you believe (1) ?

Bill

(1) > (I think its not possible to have one

observe_field for a group of radio buttons).

(2) > Now, the problem is that when I click on one radio

button, all the observers get trigerred,

Given the observed behavior in (2), what makes you believe (1) ?

Well, I don’t conclude (1) from (2). I believe (1) simply because as I
said in the reply above, the ‘value’ is appended to the id, which makes
the id’s different for all the buttons. Which means that a single
observe_field won’t work for a group of button.

Actually I think I made a little mistake by saying that “when I click on
one radio button, all the observers get trigerred”. In fact, as one
would expect, the observers that get triggered are the ones for the
radio button that gets deselcted and the one that gets selected.

Hi Aditya,

Can you tell me how to write observers with radio buttons. I am new to
rails.
Please send me code snippets if possible.

Thanks,
Nitin.
Aditya R. wrote:

Hi,

I have observers for a group of radio buttons, an observe_field for each
radio button (I think its not possible to have one observe_field for a
group of radio buttons).

Now, the problem is that when I click on one radio button, all the
observers get trigerred, so the method which the observe_field calls
gets the wrong result. I just want that method to get the radio button
that is clicked, which seems quite obvious, no?

Any idea how to do this? Help would be greatly appreciated!

Thanks,

Aditya

Hi Nitin,

Please post the code you’re having trouble with. Or Google ‘rails
observe_field radio_button’.

Best regards,
Bill