Thursday, April 24, 2008

JavaScript: Drop Down Menus

In case you ever wondered how to do this here is an A List Apart article on how to do it very simply.

http://www.alistapart.com/articles/dropdowns

Please stop downloading really bad implementations and trying to hack them together. Just read this article (yes all of it) and then do it yourself. I promise you its not that hard.

*Takes your hand* Don't be scared. You'll be better for it I promise.

Monday, April 21, 2008

Javascript: Get a Value from a Drop Down Menu

To get the value:
document.getElementById( 'dropdownmenu_id' ).options[ document.getElementById('dropdownmenu_id').selectedIndex ].value


To get the Option Name:
document.getElementById('dropdownmenu_id').options[ document.getElementById('dropdownmenu_id').selectedIndex ].text


if you use prototype.js framework then you can replace the
references to 'document.getElementById' with a $

Friday, April 18, 2008

SQL: Sequence Your Result Set

Say you want to order your result set in a specific way besides just ascending or descending. Here is a simple way to do that.

SELECT your_field,
CASE WHEN your_field = 'c' THEN 0
WHEN your_field = 'a' THEN 1
WHEN your_field = 'b' THEN 2
ELSE 3
END AS order_sequence
FROM your_table
ORDER BY order_sequence

Downside is the query will return an extra field of data (order_sequence)