javascript & checkboxes
Date: 01/27/08
(Web Development) Keywords: php
I have checkbox which, when checked, hides an element on the page, and when unchecked shows it. I'm experiencing two issues with it, though:
1) I'm using the onChange event to catch when the state of the checkbox changes. This works fine in FF, but in IE the event handler only gets executed after I first click on the checkbox and then click outside (so I guess it executes when the checkbox loses focus after it's been clicked). So what should I use to make sure that an event handler gets called when the checkbox is checked/unchecked either by the mouse or the keyboard?
2) The default state of the element I'm hiding/showing is display:none;. The default value of the checkbox that controls this behavior is checked. I turned off chaching of this page (via PHP), but in FF there's still a problem: if I load the page, uncheck the checkbox (thus changing the state of the hidden element to display: block) and then hit F5 to refresh the page, after the refresh the checkbox stays unchecked but then element goes back to display: none; In IE there's no problem as after the refresh the checkbox goes back to being checked again. So in FF I need to do something after refreshing to either return the checkbox to the default state or to keep the layer visible.
Thanks.
Source: http://community.livejournal.com/webdev/462565.html