I have a small block that contains something like this: Login | Register
When the user clicks Login, the block extends below and reveals a form for the user to login. Clicking Login again hides the form again.
The same goes for when a user clicks on Register (but with a different form). If Login or Register is clicked when the other form is visible, the newly selected form should be made visible and the other should disappear.
I would like to do more than just make the forms appear out of thin air. I’m trying to get it to “dropdown” with a very small amount of lag. Similarly, it should “rollup” when the form is re-toggled.
If this is simple to do, could someone provide some code? If it is a little more involved maybe an explanation or a link that would help me figure it out myself would be very helpful.
Use a framework such as JQuery to simplify this for you. It simplifies and normalizes all the bad parts of JavaScript so coding JS can become fun again. Unless you are a guru and understand all the design flaws and inconsistencies between “JavaScript” and “JScript”, a framework is the way to go. JQuery is only one of a handful. If you don’t prefer the syntax of JQuery, you can research Mootools, Dojo, or YUI:
http://api.jquery.com/slideToggle/
Demo: http://jsfiddle.net/vNeXq/