Setting listbox height dynamically

I need to set a listbox height dynamically to match the number of selection in it. How do I do it in Client and Web.

Thanks in advance

Subject: Setting listbox height dynamically

A listbox is designed to scroll. If you do not want scrolling, then you can use a checkbox or radio button field.