The
way that I've done this one in the past is to use a [style="width:(some number)
px;"] in the select tag, but this only works for IE. So load the values into a
javascript object and write the drop down onload. For Netscape you will need to
set a dummy option with nothing but a bunch of [ ]. See the example
below:
<script
language="javascript">
<!--
function
initDropDown()
{
var dropDown =
document.MyForm.dropDown;
// reset the drop down (This is
the part of the Netscape work-around)
dropDown.length =
0;
dropDown.length =
<%=yourObject.length%>;
<%-- loop through your object
--%>
<%for (int i = 0; i <
yourObject.length; i++) { %>
dropDown.options[<%=i%>] = new
Option(<%=yourObject{i]%>,<%=yourObject{i]%>);
<%}%>
}
//-->
</script>
<%-- Call the Javascript function onload (I'm not
sure if I've done the JSP comments correctly it's
late)--%>
<body
>
<form name="MyForm">
<select name="dropDown" style="width:
150px;">
<option
value=""> </option>
</select>
</form>
</body>
Hopefully this helps. The blank option tricks Netscape
to draw the select to the width of the spaces. Then onload the select
is emptied and filled with your values. Adding the style attribute to the select
tag will keep IE from redrawing the drop down based on the length of the
largest text value. The result should be a fixed width drop
down.
I
haven't tested the code above (obviously), but this same idea is
how I've overcome the problem in the past.
Good
Luck!!
David
Eaves
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of JSP
Sent: Tuesday, February 08, 2000 8:58 PM
To: [EMAIL PROTECTED]
Subject: Re: fix size of select itemI think it is not possible to fix the size of the list box.The list gets automatically sized as per the size of thelargest element.AdminJava Forum----- Original Message -----From: [Your Full Name] <[EMAIL PROTECTED]>To: <[EMAIL PROTECTED]>Sent: Wednesday, January 26, 2000 8:08 PMSubject: fix size of select item> how can i fix the size of list box in html .
> i am populating the list box from database .
> its size changes according to the first option .
> i want to fix the size of selection box.
>
>
> -
>
>
> Visit http://www.niit.com for eCommerce Solutions.
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
>
