Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select box resizing

Status
Not open for further replies.

JennB

Programmer
Feb 3, 2002
29
CA
Hi,

I have a select box that is being filled from a database. The problem is that one or two items from the database are super long so the select box sizes itself to the longest option. Is there a way to have the box stay a certain size until an option is selected and then resize to fit the option?

Or, is there a way to scroll the select box horizontally?

Thanks.

J
 
As far as I know there isn't a way to scroll it horizantally, but you could dynamically size it. Try this:
Code:
<select style=&quot;width:150px;&quot; onChange=&quot;this.style.width=this.options[this.selectedIndex].text.length * 7.5;document.getElementById('txt').value=this.options[this.selectedIndex].text.length * 8;&quot;>

This way it will start at width 150 but as they change what they select it will extend it's width to hold the string. 7.5 is a guestimate, it should probably be a little smaller, butthis will depend on font size.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top