views:

46

answers:

1

I'm trying to use javascript to code up a dynamic form, where elements are shown or hidden based on whether or not checkboxes are selected.

For the most part, it works okay. I defined methods that read the value of the checkbox, and rearrange the page accordingly, and then set them to the checkboxes' onclick methods. I then also set them up to run on document loading once so that the page renders correctly on refresh by the user, with code like this Event.observe(window, 'load', manageCheckbox1); (this uses the Prototype library to set it to run on loading; I'm not really sure why this is better than just a raw call to the function placed in the html after all relevant elements but this is how I've seen others do it).

However, the trouble with this approach is that the page is visible for a split second on load before the javascript is run, and then all the elements jump as the javascript inserts or removes elements.

Is there a better way to do this to avoid that unpleasant jumping effect?

+1  A: 
Gaby
updated with code samples..
Gaby
That's good idea. What's the best way to structure this, though, so as to not leave non-javascript clients in the cold? It seems like I would have to make it visible before javascript is run, but then I run into the jumping problem again?
WIlliam Jones
Hmm.. this would require a little 'hack'. define the just_loading rule by using javascript and document.write .. (update in answer)
Gaby