RJS

Hi Kad,
Kad Kerforn wrote:

I am trying to write my first RJS script to uncheck
all radio buttons in a div #network_radio_btns

page.select('#network_radio_btns input').each do |element|
element.set_attribute('checked', 'false')
end

I tested the loop : alert(index) and I can see all indexes but ...
how can I change an option ?.... not the value

I'd probably just render a new partial rather then trying to reset the button. If you really need to go this route, I think the visible properties of a radio button depend on the value being nil for unchecked. So you might need to add

element.set_attribute('value', nil)

I haven't tested it though.

hth,
Bill

maybe i'm missing something, but why would you need to do this using
rjs? from your example, you're making a call to the server, which is
returning javascript to uncheck all the checkboxes in a div. why not
just use straight javascript and skip the server altogether?

assuming all the checkboxes are in a form element, you can do
something like this (requires prototype):

<form id="my_form">
...
</form>
<%= link_to_function "CHECK ALL", "check_all('my_form')" -%>
<%= link_to_function "UNCHECK ALL", "uncheck_all('my_form')" -%>

<script type="text/javascript">
function check_all(form) {
  Form.getInputs(form, 'checkbox').each( function(cb) {
                                                        cb.checked = true;
                                                       });
}

function uncheck_all(form) {
  Form.getInputs(form, 'checkbox').each( function(cb) {
                                                        cb.checked = false;
                                                       });
}
</script>