how do I know checkbox if a checkbox is checked after F5?

I create some checkboxs with check_box_tag in a rhtml, when I check the
checkbox, I change the css class of the checkbox with javascript,
everything is fine, however, when I press on F5 to refresh my page, the
checkbox is still checked, but the css class is turned back to the
uncheck... What happens exactly when I press F5? Is the rhtml page
rebuilt??? or what, and where the checkbox information is stored (since
it has kept its checked state) in params, session or ...?

Is this firefox? I've noticed that reloads will cause the edits to the form you've made since initial load to be kept, isntead of the form resetting itself. If that's what you're experiencing, then click in the url bar and just hit return. That seems to cause it to not only reload, but reset the form as well.

-philip

use some javascript. prototype has some nice functionality to get at
form elements

var checkboxes = $('form_id').getInputs('checkbox');

checkboxes.each(function(cb) {
                             if (cb.checked == true) {
                                // if using class attribute
                                Element.addClassName(cb, 'checked_class');
                                // or if using style attribute
                                // Element.setStyle(cb,
{'backgroundColor':'#FF0000'})
                             }
                         });

or something to that effect.

no, the server has no way to know you pressed 'F5'.

as already discussed, the steps involved are:

1) initial page load
2) you check some checkboxes off, and your styles are applied
(assuming you use an onClick event)
3) you press F5, telling browser to request the page again
4) page is (re)loaded
5) your browser, remembering what you did in the form, repopulates the
form. NOTE: no onclick events are fired when your browser repopulates
the form.

the next step if for you to write some javascript to set the styles on
the checkboxes that have been checked by the browser. see the example
i provided to you.

Let’s not forget that there’s more than one shortcut for reloading a page. CTRL + “R”, SHIFT + CTRL + “R”, maybe more.

RSL