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

Hi,

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 …?

Thanks you very much

Sayoyo

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

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 …?

when you press F5 you will usually get a new petition of the page to the
server. It depends on browser cache configuration anyway. Maybe images
are not reloaded and .js by default wouldn’t either, but rails appends a
chunk of numbers to gracefully reload js without wiping the cache.

So, when the server gets the new petition it will reload the action and,
as you say, ‘rebuild’ the rhtml (assuming you are in development
environment and didn’t change the defaults).

About the client side values, such as the selected check boxes, it’s
your browser the one populating the values again after hitting F5. On
Firefox you can force a full reload with Ctrl+F5, and not sure if on IE
was Shift+F5.

good luck,

javier ramirez

Estamos de estreno… si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!

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.

Thanks you for all the information!!!

Yes, I’m using firefox on linux fedora core 5. I have try to ctrl+F5,
but it seems not to reload anything…

thanks for the hint for javascript code, but I wonder if ruby can do the
same thing… like detecting if F5 is pressed???

Thanks you very much!!!

Sayoyo

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.

Good day,

i dont get why u need to do this but you can use session to store
newly checked checkboxes even if user not pressed Submit.

just make onclick event for each checkbox(javascript), that insert to
session coookie id of checkbox.

function doRemember(domID)
{
PUT small verification code to determine wheither checkbox are
checked or not
if checked call Set_Cookie(“checkbox_” + domID, 1);
if unchecked call Set_Cookie(“checkbox_” + domID, 0);
}

function Set_Cookie(name,value)
{

var cookieString = name + "=" +escape(value);
document.cookie = cookieString;

}
<--------------------->

okay, now when u reload page and running in loop of some model just
check session cookie with “checkbox_?” names,
split it by "" and if somemodel.id = ? (of checkbox, and checkbox? =

  1. then html attribute of this will be checked=“checked”

Make something that will make hash of all cookie checkboxes like:
checkboxes … [id, value] [id, value]
values will be 0 or 1
and id will be value after checkbox_?

Offcourse you should run another loop inside instance loop, to check
all checkbox_? cookies.
box.each do | box |
attrib = “”
checkboxes.each do | checkbox |
attrib = “checked=”
if checkbox.id == box.id
checkbox.value == 1 ? attrib += “‘checked’” : attrib +=
“‘none’”
end
end
end


Thats all for now, maybe i made somewhere mistake, didnt checked it,
but it should work.

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

RSL